Java Long to IP Address long2ip(long ip)

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

Description

longip

License

Open Source License

Declaration

public static String long2ip(long ip) 

Method Source Code

//package com.java2s;
/*// w  w w  . ja  v  a 2 s.  c  om
 Copyright 2010 Jeremie Gottero, Nicolas Bosc
    
 This file is part of Fallen Galaxy.
    
 Fallen Galaxy is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 Fallen Galaxy is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Affero General Public License for more details.
    
 You should have received a copy of the GNU Affero General Public License
 along with Fallen Galaxy. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String long2ip(long ip) {
        byte[] bytes = new byte[4];

        bytes[0] = (byte) ((ip & 0xff000000) >> 24);
        bytes[1] = (byte) ((ip & 0x00ff0000) >> 16);
        bytes[2] = (byte) ((ip & 0x0000ff00) >> 8);
        bytes[3] = (byte) (ip & 0x000000ff);
        String result = new String(String.valueOf((int) bytes[0]) + "." + String.valueOf((int) bytes[1]) + "."
                + String.valueOf((int) bytes[2]) + "." + String.valueOf((int) bytes[3]));
        return result;

    }
}

Related

  1. long2Ip(final long ip)
  2. long2ip(long address)
  3. long2ip(long ip)
  4. long2ip(long ip)
  5. long2ip(long ip)
  6. long2ip(long ipLong)