/**
* Converts an integer representation of an IP address to a string representation.
*
* IP Address @param IP 32-bit integer
* @return The IP address represented by the fractional point
*/
public static final String Long2ip (final long IP) {
Final long[] mask = {0x000000ff, 0x0000FF00, 0x00ff0000, 0xff000000};
Final StringBuilder ipAddress = new StringBuilder ();
for (int i = 0; i < mask.length; i++) {
Ipaddress.insert (0, (IP & mask[i]) >> (i * 8));
if (I < mask.length-1) {
Ipaddress.insert (0, ".");
}
}
return ipaddress.tostring ();
}
BYTES[2] = (byte) ((V & 0x0000ff00) >>> 8);
The type V int is a 32-bit 0x0000ff00 is also 32 bits (0000 0000 1111 1111 0000 0000)
The function of the v&0x0000ff00 is to shield the last V 8 bits (into 0) and then move the unsigned 8-bit to the right, which is the so-called high 8-bit.
Similarly v & 0x000000ff); The function is to get eighth place.
How to convert an integer representation of an IP address to a string representation in Java