Java Long to IP Address longToIp(String ip)

Here you can find the source of longToIp(String ip)

Description

Converts a String IP address to a long String representation.

License

Open Source License

Parameter

Parameter Description
ip the IP address to convert

Return

a long String representation of the IP address

Declaration

public static String longToIp(String ip) 

Method Source Code

//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();

    }
}

Related

  1. longToIp(long i)
  2. longToIp(long ip)
  3. longToIp(long ip)
  4. LongToIp(long longIp)
  5. longToIp(long longValue)
  6. longToIpAddress(long ip)
  7. longToIPv4(final long ipaddress)
  8. longToIpV4(long ip)
  9. longToIpV4(long longIp)