Java Utililty Methods Long to IP Address

List of utility methods to do Long to IP Address

Description

The list of methods to do Long to IP Address are organized into topic(s).

Method

StringlongToIpV4(long ip)
long To Ip V
StringBuilder sb = new StringBuilder(15);
for (int i = 0; i < 4; i++) {
    sb.insert(0, Long.toString(ip & 0xff));
    if (i < 3) {
        sb.insert(0, '.');
    ip >>= 8;
return sb.toString();
StringlongToIpV4(long longIp)
convert ipV4 Long format to String.
final long numBeyond = 0xffffffffL;
if (longIp > numBeyond) {
    return "";
final int threeByteSize = 24;
final int threeByteMask = 0x00ffffff;
final int twoByteSize = 16;
final int twoByteMask = 0x0000ffff;
...
StringlongToIpV4(long longIp)
long To Ip V
int octet3 = (int) ((longIp >> 24) % 256);
int octet2 = (int) ((longIp >> 16) % 256);
int octet1 = (int) ((longIp >> 8) % 256);
int octet0 = (int) ((longIp) % 256);
return octet3 + "." + octet2 + "." + octet1 + "." + octet0;
StringlongToIpV6(long highBits, long lowBits)
convert ipV6 Long format to String.
final int oneByteSize = 8;
final int v6MaxSegment = 8;
final int twoByteSize = 16;
final int fourByteMask = 0xFFFF;
short[] shorts = new short[v6MaxSegment];
String[] strings = new String[shorts.length];
for (int i = 0; i < v6MaxSegment; i++) {
    if (i >= 0 && i < v6MaxSegment / 2) {
...