Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

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 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What 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 ??

- M. April 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I meant something like this.

ezinearticles.com/?How-to-Convert-an-IP-Address-to-10-Digits-Decimal-Number&id=1716788

- Artin April 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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;
        }

- insigniya April 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You are right Insigniya.

- Artin April 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

or more simply...

int IpToInt(String ip) {
  String[] sIps = ip.split(".");
  
  int result = 0;

  for(int i = sIps.length - 1; i >= 0; i--) {
    int n = Integer.parseInt(sIps[i]);
    result += Math.pow(256, 3-i) + n;
  }

  return result;

}

- Anonymous April 22, 2011 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More