Check out InetAddress at javadocs. These functions are not directly supported by the standard API, but you can extract both views using this class. A small example:
InetAddress address = InetAddress.getLocalHost(); byte[] byteAddress = address.getAddress(); System.out.println(Arrays.toString(byteAddress)); System.out.println(address.getHostAddress());
(Keep in mind that bytes are signed.)
If you have long-s, then yo can use ByteBuffer for quick and convenient coversion. Methods: putLong (), then array ().
source share