Microsoft Interview Question for Software Engineer / Developers






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

String ip = "244.21.233.11";
		String[] bits = ip.split("\\.");
		int ip_addr = 0;
		for (String bit : bits) {
			ip_addr = ip_addr << 8 | Integer.parseInt(bit);
		}
		System.out.println(Integer.toBinaryString(ip_addr));

- Anonymous April 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think here they are asking to parse from left to right and not to use some std methods...

- agarwalvipin April 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>

int main ()
{
char str[] ="198.160.9.10";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str,".");
while (pch != NULL)
{
printf ("%s\n",pch);
int l=strlen(pch);
int i=0,num=0;
while(i<l){
num*=10;
num+=pch[i++]-'0';
}
pch = strtok (NULL, ".");
printf("\nint value is :%d\n",num);
}
return 0;
}

Please comment!!

- CodeNotguru April 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

why this ?

pch = strtok (NULL, ".");

- shoonya.mohit May 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The first strtok is outside the loop. For subsequent calls to strtok, the first argument is NULL. do a man strtok.

- Anonymous July 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="c" line="1" title="CodeMonkey1286" class="run-this"> void TokenizeIpAddressToIntegers(char* address)
{
int begin = 0, end = 0;

while(address[end])
{
if(address[end] == '.')
{
PrintInt(address, begin, end);
end++;
begin = end;
}
else
{
end++;
}
}

PrintInt(address, begin, end);
}

void PrintInt(char *address, int begin, int end)
{
int num = 0;
int length = end - begin;

while(length > 0)
{
int digit = address[begin] - 48;
num = num + digit * pow(10.0, (length-1));
length--;
begin++;
}

printf("%d\n", num);
}

int main()
{
char *address = "192.168.20.002";
TokenizeIpAddressToIntegers(address);
}</pre>

- Anonymous August 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="c" line="1" title="CodeMonkey24878" class="run-this"> void TokenizeIpAddressToIntegers(char* address)
{
int begin = 0, end = 0;

while(address[end])
{
if(address[end] == '.')
{
PrintInt(address, begin, end);
end++;
begin = end;
}
else
{
end++;
}
}

PrintInt(address, begin, end);
}

void PrintInt(char *address, int begin, int end)
{
int num = 0;
int length = end - begin;

while(length > 0)
{
int digit = address[begin] - 48;
num = num + digit * pow(10.0, (length-1));
length--;
begin++;
}

printf("%d\n", num);
}

int main()
{
char *address = "192.168.20.002";
TokenizeIpAddressToIntegers(address);
}</pre>

- Anonymous August 07, 2010 | Flag Reply


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