I want to convert a string value (in hexadecimal) to an IP Address. How can I do it using Java?
Hex value: 0A064156
IP: 10.6.65.86
This site gives me the correct result, but I am not sure how to implement this in my code.
Can it be done directly in an XSLT?
The accepted answer has a requirement that, the hex must be even-length. Here is my answer:
You can use the following method:
try this
DatatypeConverter is from standard
javax.xml.bind
packageYou can split your hex value in groups of 2 and then convert them to integers.
Code:
Output:
You can split it 2 characters, and then use Integer.parse(string, radix) to convert to integer values
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html#parseInt(java.lang.String,int)
UPDATE: Link for newer documentation: https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-
}