Java Long to IP Address longToIpV4(long longIp)

Here you can find the source of longToIpV4(long longIp)

Description

convert ipV4 Long format to String.

License

Open Source License

Parameter

Parameter Description
longIp ipV4 long value.

Return

ipv4 string.

Declaration

public static String longToIpV4(long longIp) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  w w  w .  j  a v  a 2  s  .  com*/
     * convert ipV4 Long format to String.
     * 
     * @param longIp
     *            ipV4 long value.
     * @return ipv4 string.
     */
    public static String longToIpV4(long longIp) {
        final long numBeyond = 0xffffffffL;
        if (longIp > numBeyond) {
            return "";
        }
        final int threeByteSize = 24;
        final int threeByteMask = 0x00ffffff;
        final int twoByteSize = 16;
        final int twoByteMask = 0x0000ffff;
        final int oneByteSize = 8;
        final int oneByteMask = 0x000000ff;
        return String.format("%d.%d.%d.%d", (longIp >>> threeByteSize) & oneByteMask,
                (longIp & threeByteMask) >>> twoByteSize, (longIp & twoByteMask) >>> oneByteSize,
                longIp & oneByteMask);
    }
}

Related

  1. longToIp(String ip)
  2. longToIpAddress(long ip)
  3. longToIPv4(final long ipaddress)
  4. longToIpV4(long ip)
  5. longToIpV4(long longIp)
  6. longToIpV6(long highBits, long lowBits)