Java Long to String long2String(final long ip)

Here you can find the source of long2String(final long ip)

Description

Converts a long value representing an IP address to a standard IP address (dotted decimal format).

License

Open Source License

Parameter

Parameter Description
ip long value representing an IP address

Return

A standard IP address

Declaration

public static String long2String(final long ip) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 GigaSpaces Technologies Ltd. All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//  www. ja  va2s  .  c om
 ******************************************************************************/

public class Main {
    /**
     * Converts a long value representing an IP address to a standard IP address (dotted decimal format).
     * 
     * @param ip
     *            long value representing an IP address
     * @return A standard IP address
     */
    public static String long2String(final long ip) {
        final long a = (ip & 0xff000000) >> 24;
        final long b = (ip & 0x00ff0000) >> 16;
        final long c = (ip & 0x0000ff00) >> 8;
        final long d = ip & 0xff;

        return a + "." + b + "." + c + "." + d;
    }
}

Related

  1. long2sortableStr(long val)
  2. Long2Str(long i)
  3. Long2String(final long value)
  4. long2string(long lng, StringBuilder buff)
  5. long2string(long longdata)
  6. long2String(long x)