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
<
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.