Convert long to ip address - Android java.net

Android examples for java.net:IP Address

Description

Convert long to ip address

Demo Code

public class Main{

    public static String long2ip(long ip) {

        StringBuffer sb = new StringBuffer();
        sb.append(String.valueOf((int) (ip & 0xff)));
        sb.append('.');
        sb.append(String.valueOf((int) ((ip >> 8) & 0xff)));
        sb.append('.');
        sb.append(String.valueOf((int) ((ip >> 16) & 0xff)));
        sb.append('.');
        sb.append(String.valueOf((int) ((ip >> 24) & 0xff)));
        return sb.toString();
    }//  w w  w .j a v a2  s .c o m

}

Related Tutorials