192 x 256^3 + 168 x 256^2 + 1 x 256^1 + 1 x 1
3221225472 + 11010048 + 256 + 1 = 3232235777
http://3232235777IPアドレスを10進数で表す2つの方法:
![]() |
バイナリ<で(1 x 256^1)を計算する例 /td> |
public class IP_Decimale {Output
public static void main(String[] zero) {
String ip = "192.168.1.1";
//10進数のIPアドレス
long iplong = IPenBase10(ip);
System.out.println(iplong);
}
public static long IPenBase10(文字列 IP アドレス) {
long decimal = 0;
//数字はドットで区切られます
//それぞれを配列のボックスに格納します
String[] arrayIP = IP.address.split("\\.");
//右から左へ
for (int i = 3; i >= 0; i--) {
//long
に変換 long ip = Long.parseLong(arrayIP[3 - i]);
//(i*8)ビットを左にシフトし、合計
long bitshift= ip <<(i*8);
10 進数 += ビットシフト;
System.out.println(ip+" <<"+(i*8)+" : "+ビットシフト);
}
10 進数を返します。
}
}
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;
文字列[] arrayIP = IP.address.split("\\.");
//右から左へ
for (int i = 0; i<=3; i++) {
long ip = Long.parseLong(arrayIP[i]);
long puiss= ip * (long) Math.pow(256, 3-i);
10進数+=累乗;
System.out.println(arrayIP[i] +": "+puiss);
}
10 進数を返します。
}
Please disable your ad blocker and refresh the window to use this website.