private static String intToString(int i) {
return ( (i& 0xFF) + "." +((i >>8)& 0xFF)+"."+((i>>16)&0xFF)+"."+((i >> 24 )&0xFF));
}
private static int stringToInt(String addrString)
throws UnknownHostException {
try {
if (addrString == null)
return 0;
String[] parts = addrString.split("\\.");
if (parts.length != 4) {
throw new UnknownHostException(addrString);
}
int a = Integer.parseInt(parts[0]);
int b = Integer.parseInt(parts[1]) << 8;
int c = Integer.parseInt(parts[2]) << 16;
int d = Integer.parseInt(parts[3]) << 24;
return a | b | c | d;
} catch (NumberFormatException ex) {
throw new UnknownHostException(addrString);
}
}
android里ip,mac,gateway等参数其int和String类型互转
最新推荐文章于 2021-05-27 19:29:38 发布