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]));
}
}
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]));
}
}
相关文章推荐
- How to convert an IPv4 address into a integer in C#?
- [Ramda] Convert a QueryString to an Object using Function Composition in Ramda
- How Do I Convert an Integer to a String in Excel VBA
- safe convert string to integer function
- How can I convert a floating-point value to an integer in C?
- Write a C program to find the parity of an unsigned integer
- Given an integer, write a function to determine if it is a power of two
- In Java, how do I read/convert an InputStream to a String? - Stack Overflow
- Write a function to find the longest common prefix string amongst an array of strings.
- Implement atoi to convert a string to an integer.
- leetcode 8 Implement atoi to convert a string to an integer.
- Write a program to convert string to number without using library function。
- Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits i
- Write a function to find the longest common common string amongst an array of strings.
- convert ip address string to unsigned int
- leetCode Given an integer (signed 32 bits), write a function to check whether it is a power of 4
- 4、Write a function to find the longest common prefix string amongst an array of strings
- How can I convert a floating-point value to an integer in C?
- Implement atoi to convert a string to an integer.
- Function to Convert Only First Letter Capital of each word in a sentence