0
byte[] bytes = BigInteger.valueOf(Wifi.getDhcpInfo().gateway).toByteArray();
InetAddress address = null;

Выдает только : /1.1.168.192, а я хочу 192.168.1.1. Как это сделать?

4
  • Сделать реверс массива.
    – Alexis
    19 июн 2015 в 20:20
  • обязательно нужно в байтах? String gateway = String.valueOf(Wifi.getDhcpInfo().gateway); не подходит?
    – Rishka
    19 июн 2015 в 20:31
  • вот код 'byte[] unpack(int bytes) { return new byte[] { (byte)((bytes >>> 24) & 0xff), (byte)((bytes >>> 16) & 0xff), (byte)((bytes >>> 8) & 0xff), (byte)((bytes ) & 0xff) }; } byte[] bytes = unpack(Integer.parseInt(String.valueOf(Wifi.getDhcpInfo().gateway))); InetAddress address = null; try { address = InetAddress.getByAddress(bytes); } catch (UnknownHostException e) { e.printStackTrace(); } twMonitor.setText("Local Gateway: "+address);' 19 июн 2015 в 20:59
  • @GamerDeveloper дополни свой ответ, пожалуйста. Как ты понимаешь, такое читать невозможно
    – Rishka
    19 июн 2015 в 22:13

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.