Amazon Interview Question
Software Engineer / DevelopersWhat is meant by this question ?
float IpToD( string ipaddress) which will return the ip adress to some float ?? so are we intending to create String DToIp(float ipaddress) later ??
If I have understood the question clearly.. here is the code to convert IPv4 to number.
static uint Transform(string input)
{
string[] str = input.Split('.');
uint final = 0;
uint number = 0;
for (int i = 0; i < str.Length;i++ )
{
number = Convert.ToUInt32(str[i]);
number = number << ((str.Length - i -1) * 8);
final = final | number;
Console.WriteLine();
}
return final;
}
If the question is not clear, given an IP="192.168.0.1", determine a formula to convert the IP string to an integer.
- Artin April 09, 2011