Here you can find the source of longToIpV4(long longIp)
Parameter | Description |
---|---|
longIp | ipV4 long value. |
public static String longToIpV4(long longIp)
//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); } }