Java Long to IP Address longToIpV4(long ip)

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

Description

long To Ip V

License

Open Source License

Declaration

public static final String longToIpV4(long ip) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 BowenCai.//from  w  w  w.  j  av  a 2 s. co  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     BowenCai - initial API and implementation
 ******************************************************************************/

public class Main {
    public static final String longToIpV4(long ip) {
        StringBuilder sb = new StringBuilder(15);

        for (int i = 0; i < 4; i++) {
            sb.insert(0, Long.toString(ip & 0xff));

            if (i < 3) {
                sb.insert(0, '.');
            }
            ip >>= 8;
        }

        return sb.toString();
    }
}

Related

  1. LongToIp(long longIp)
  2. longToIp(long longValue)
  3. longToIp(String ip)
  4. longToIpAddress(long ip)
  5. longToIPv4(final long ipaddress)
  6. longToIpV4(long longIp)
  7. longToIpV4(long longIp)
  8. longToIpV6(long highBits, long lowBits)