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

Gives out only: /1.1.168.192, and I want 192.168.1.1. How to do it?

  • Reverse array. - Alexis
  • do you need bytes? String gateway = String.valueOf(Wifi.getDhcpInfo().gateway); not suitable? - Rishka
  • here is the code '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); ' - GamerDeveloper
  • @GamerDeveloper add your answer, please. As you know, this is impossible to read - Rishka

0