您的位置:首页 > 其它

Write a function to convert an IPv4 Address in string format to an unsigned integer

2012-02-28 20:56 387 查看
import java.lang.*;
public class IPtoNum
{
public static double IPAddressToNumber(String IPaddress1)
{
int i;
String [] arrDec=null;
double num = 0;
if (IPaddress1 == "")
{
return 0;
}
else
{
String delimiter = "\\.";
arrDec = IPaddress1.split(delimiter);
System.out.println(arrDec.length);
for(i = arrDec.length - 1; i >= 0 ; i --)
{
num += ((Integer.parseInt(arrDec[i])%256) * Math.pow(256 ,(3 - i )));
}
return num;
}
}
public static void main(String args[])
{
System.out.println(IPAddressToNumber(args[0]));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: