有人可以向我解释为什么我得到这些结果?
public static int ipv4ToInt(String address) {
int result = 0;
// iterate over each octet
for(String part : address.split(Pattern.quote("."))) {
// shift the previously parsed bits over by 1 byte
result = result << 8;
System.out.printf("shift = %d\n", result);
// set the low order bits to the current octet
result |= Integer.parseInt(part);
System.out.printf("result = %d\n", result);
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
对于ipv4ToInt("10.35.41.134"),我得到:
shift = 0
result = 10
shift = 2560
result = 2595
shift = 664320
result = 664361 …