复制代码 代码如下:
public class Ip {
public static void main(String[] args) {
System.out.print(ip2int("10.0.3.193"));
}
public static long ip2int(String ip) {
String[] items = ip.split("//.");
return Long.valueOf(items[0]) << 24
| Long.valueOf(items[1]) << 16
| Long.valueOf(items[2]) << 8
| Long.valueOf(items[3]);
}
}
复制代码 代码如下:
public class Ip {
public static void main(String[] args) {
System.out.print(int2ip(167773121));
}
public static String int2ip(long ipInt) {
StringBuilder sb = new StringBuilder();
sb.append(ipInt & 0xFF).append(".");
sb.append((ipInt >> 8) & 0xFF).append(".");
sb.append((ipInt >> 16) & 0xFF).append(".");
sb.append((ipInt >> 24) & 0xFF);
return sb.toString();
}
}
新闻热点
疑难解答
图片精选