192 x 256^3 + 168 x 256^2 + 1 x 256^1 + 1 x 1
3221225472 + 11010048 + 256 + 1 = 3232235777
http://3232235777Zwei Möglichkeiten, die IP-Adresse in einer Dezimalzahl auszudrücken:
![]() |
Beispiel für die Berechnung von (1 x 256^1) in binärem |
public class IP_Decimale {Output
public static void main(String[] zero) {
String ip = "192.168.1.1";
//IP-Adresse in dezimal
lang iplong = IPenBase10(ip);
System.out.println(iplong);
}
public static long IPenBase10(String IP address) {
long decimal = 0;
//die Zahlen werden durch Punkte getrennt
//setzen Sie jede in ein Feld im array
String[] arrayIP = IP.address.split("\\.");
//von rechts nach links
for (int i = 3; i >= 0; i--) {
//convert to long
long ip = Long.parseLong(arrayIP[3 - i]);
//shift (i*8) Bits nach links und sum
long bitshift= ip < < (i*8);
dezimal += bitshift;
System.out.println(ip+" < < "+(i*8)+" : "+Bitverschiebung);
}
dezimal zurückgeben;
}
}
192 < < 24 : 3221225472
168 < < 16 : 11010048
1 < < 8 : 256
1 < < 0 : 1
result: 3232235777
public static long IPenBase10puiss(String IP address) {Referenzen:
long decimal = 0;
String[] arrayIP = IP.address.split("\\.");
//von rechts nach links
for (int i = 0; i<=3; i++) {
long ip = Long.parseLong(arrayIP[i]);
long puiss= ip * (lang) Math.pow(256, 3-i);
dezimal += Potenzen;
System.out.println(arrayIP[i] +": "+puiss);
}
dezimal zurückgeben;
}
Please disable your ad blocker and refresh the window to use this website.