192 x 256^3 + 168 x 256^2 + 1 x 256^1 + 1 x 1
3221225472 + 11010048 + 256 + 1 = 3232235777
http://3232235777IP 주소를 십진수로 표현하는 두 가지 방법:
![]() |
이진수로 (1 x 256^1) 계산 예: |
public class IP_Decimale {Output
public static void main(String[] zero) {
String ip = "192.168.1.1";
//십진수 단위의 IP 주소
길이 iplong = IPenBase10(ip);
System.out.println(iplong);
}
public static long IPenBase10(문자열 IP 주소) {
긴 십진수 = 0;
//숫자는 점으로 구분됩니다
//배열의 상자에 각각을 넣습니다
String[] arrayIP = IP.address.split("\\.");
//오른쪽에서 왼쪽으로
for (int i = 3; i >= 0; i--) {
//long
long ip = Long.parseLong(arrayIP[3 - i]);
//왼쪽으로 (i*8) 비트를 이동하고 sum
long bitshift= ip < < (나*8);
십진수 += 비트 시프트;
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(문자열 IP 주소) {참조:
긴 십진수 = 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);
십진수 += 거듭제곱;
System.out.println(arrayIP[i] +": "+puiss);
}
10진수를 반환합니다.
}
Please disable your ad blocker and refresh the window to use this website.