Apr 15

The BigDecimal class makes this really easy as it has a method toByteArray() that returns exactly what we need. Just need to create a BigDecimal and call the method.

   byte[] bytes = new BigInteger(hexString, 16).toByteArray();

written by objects \\ tags: , ,

Oct 01

Use the getAddress() method in the InetAddress class.

InetAddress address = 
byte[] bytes = address.getAddress();
for (byte b : bytes)
    System.out.println(b & 0xFF);

written by objects \\ tags: , ,