Java IP Address to String ipToString(long ip)

Here you can find the source of ipToString(long ip)

Description

ip To String

License

Open Source License

Declaration

public static String ipToString(long ip) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static char[][] nums256;
    private static char[] dot;

    public static String ipToString(long ip) {
        return ipToString(new StringBuilder(), ip).toString();
    }//from w  ww.j a va 2  s . c  o m

    public static StringBuilder ipToString(StringBuilder sb, long ip) {
        sb.append(nums256[(int) (ip >> 24) & 0xFF]);
        sb.append(dot);
        sb.append(nums256[(int) (ip >> 16) & 0xFF]);
        sb.append(dot);
        sb.append(nums256[(int) (ip >> 8) & 0xFF]);
        sb.append(dot);
        sb.append(nums256[(int) (ip) & 0xFF]);
        return sb;
    }

    public static StringBuilder ipToString(StringBuilder sb, int[] ip) {
        sb.append(nums256[ip[0] & 0xFF]);
        sb.append(dot);
        sb.append(nums256[ip[1] & 0xFF]);
        sb.append(dot);
        sb.append(nums256[ip[2] & 0xFF]);
        sb.append(dot);
        sb.append(nums256[ip[3] & 0xFF]);
        return sb;
    }
}

Related

  1. ipToIPv4Str(byte[] ip)
  2. ipToString(final byte[] address)
  3. ipToString(final byte[] bytes)
  4. IpToString(int address)
  5. IPToString(int intIP)
  6. ipv4ToBinaryStr(int ipv4)
  7. ipV4ToLong(final String ipaddress)
  8. ipv4ToStr(int ipv4)
  9. ipv4ToString(byte[] address)