192 x 256^3 + 168 x 256^2 + 1 x 256^1 + 1 x 1
3221225472 + 11010048 + 256 + 1 = 3232235777
http://3232235777Two ways to express the IP address in a decimal number:
![]() |
Example of calculating (1 x 256^1) in binary |
public class IP_Decimale {Output
public static void main(String[] zero) {
String ip = "192.168.1.1";
//IP address in decimal
long iplong = IPenBase10(ip);
System.out.println(iplong);
}
public static long IPenBase10(String IP address) {
long decimal = 0;
//the numbers are separated by dots
//put each in a box in the array
String[] arrayIP = IP.address.split("\\.");
//from right to left
for (int i = 3; i >= 0; i--) {
//convert to long
long ip = Long.parseLong(arrayIP[3 - i]);
//shift (i*8) bits to the left and sum
long bitshift= ip < < (i*8);
decimal += bitshift;
System.out.println(ip+" < < "+(i*8)+" : "+bitshift);
}
return decimal;
}
}
192 < < 24 : 3221225472
168 < < 16 : 11010048
1 < < 8 : 256
1 < < 0 : 1
result: 3232235777
public static long IPenBase10puiss(String IP address) {References:
long decimal = 0;
String[] arrayIP = IP.address.split("\\.");
//from right to left
for (int i = 0; i<=3; i++) {
long ip = Long.parseLong(arrayIP[i]);
long puiss= ip * (long) Math.pow(256, 3-i);
decimal += powers;
System.out.println(arrayIP[i] +": "+puiss);
}
return decimal;
}
Please disable your ad blocker and refresh the window to use this website.