Returns 32-bit integer address to IPv4 address string "%d.%d.%d.%d" format. - Java java.lang

Java examples for java.lang:int Format

Description

Returns 32-bit integer address to IPv4 address string "%d.%d.%d.%d" format.

Demo Code


//package com.java2s;

public class Main {
    /***/*from  w  ww  . j a v a 2  s. c  om*/
     * Returns 32-bit integer address to IPv4 address string "%d.%d.%d.%d"
     * format.
     * 
     * @param address
     *            the 32-bit address
     * @return the raw IP address in a string format.
     */
    public static String getHostAddress(int address) {
        return ((address >>> 24) & 0xFF) + "." + ((address >>> 16) & 0xFF)
                + "." + ((address >>> 8) & 0xFF) + "."
                + ((address >>> 0) & 0xFF);
    }
}

Related Tutorials