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?
An IP address can be expressed in dotted decimal, binary, octal, or hexadecimal. While all are correct and mean the same thing, it's most common to use dotted decimal notation for IPv4 and hexadecimal (hex) for IPv6.
Users can also convert Hex File to IP by uploading the file. It also referred as XUID to IP Converter. Hex IP to Decimal converter works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.
You can split your hex value in groups of 2 and then convert them to integers.
0A = 10
06 = 06
65 = 41
86 = 56
Code:
String hexValue = "0A064156";
String ip = "";
for(int i = 0; i < hexValue.length(); i = i + 2) {
ip = ip + Integer.valueOf(hexValue.subString(i, i+2), 16) + ".";
}
System.out.println("Ip = " + ip);
Output:
Ip = 10.6.65.86.
try this
InetAddress a = InetAddress.getByAddress(DatatypeConverter.parseHexBinary("0A064156"));
DatatypeConverter is from standard javax.xml.bind
package
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With