Here you can find the source of longToIp(String ip)
Parameter | Description |
---|---|
ip | the IP address to convert |
public static String longToIp(String ip)
//package com.java2s; //License from project: Open Source License public class Main { /**// w ww . j av a2s . c o m * Converts a String IP address to a long String representation. * * @param ip the IP address to convert * @return a long String representation of the IP address */ public static String longToIp(String ip) { Long ipLong = Long.valueOf(ip); StringBuilder result = new StringBuilder(15); for (int i = 0; i < 4; i++) { result.insert(0, Long.toString(ipLong & 0xff)); if (i < 3) { result.insert(0, '.'); } ipLong = ipLong >> 8; } return result.toString(); } }