|
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();
|
|
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();
Use the getAddress() method in the InetAddress class.
InetAddress address =
InetAddress.getByName("192.168.1.1");
byte[] bytes = address.getAddress();
for (byte b : bytes)
{
System.out.println(b & 0xFF);
}
|
|
Recent Comments