Java Long to IP Address longToIp(long address)

Here you can find the source of longToIp(long address)

Description

A convenient method that accepts an IP address represented as a long and returns an integer array of size 4 representing the same IP address.

License

Open Source License

Parameter

Parameter Description
address the long value representing the IP address.

Return

An int[] of size 4.

Declaration

public static int[] longToIp(long address) 

Method Source Code

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

public class Main {
    /**// w w w  . ja  v  a 2s .c  o  m
     * A convenient method that accepts an IP address represented as a
     * long and returns an integer array of size 4 representing the same
     * IP address.
     * @param address the long value representing the IP address.
     * 
     * @return An int[] of size 4.
     */
    public static int[] longToIp(long address) {
        int[] ip = new int[4];
        for (int i = 3; i >= 0; i--) {
            ip[i] = (int) (address % 256);
            address = address / 256;
        }
        return ip;
    }
}

Related

  1. long2ip(long ip)
  2. long2ip(long ipLong)
  3. long2IP(long ipLong)
  4. long2IP(long proper_address)
  5. long2IpAdress(long src)
  6. longToIp(long i)
  7. longToIp(long i)
  8. longToIp(long ip)
  9. longToIp(long ip)