Here you can find the source of longToIp(long i)
public static String longToIp(long i)
//package com.java2s; public class Main { private static final int SLASHNET_VALUE = 32; private static final String DOT = "."; private static final int X_FF = 0xFF; private static final int EIGHT = 8; private static final int SIXTEEN = 16; private static final int TWENTY_FOUR = 24; private static final String SLASH = "/"; private static final int NUMBER_OF_BITS_IN_IP = 32; public static String longToIp(long i) { long ipOnly = i & 0xFFFFFFFF; long netmask = (long) (i >> NUMBER_OF_BITS_IN_IP); StringBuffer result = new StringBuffer(); result.append((ipOnly >> TWENTY_FOUR) & X_FF); result.append(DOT);//from w w w . j av a 2s. c om result.append((ipOnly >> SIXTEEN) & X_FF); result.append(DOT); result.append((ipOnly >> EIGHT) & X_FF); result.append(DOT); result.append(ipOnly & X_FF); String fullIpAddress = ""; if (netmask > 0) { fullIpAddress = result.toString() + SLASH + slashnetFromAddrs(netmask); } else fullIpAddress = result.toString(); return fullIpAddress; } public static int slashnetFromAddrs(long addrs) { return (int) (SLASHNET_VALUE - log2(addrs)); } private static double log2(double d) { return Math.log(d) / Math.log(2.0); } }