Interview Question for Developer Program Engineers


Country: India




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

short convert_short(short in) 
{ 
  short out; 
  char *p_in = (char *) ∈ 
  char *p_out = (char *) &out; 
  p_out[0] = p_in[1]; 
  p_out[1] = p_in[0];   
  return out; 
} 

long convert_long(long in) 
{ 
  long out; 
  char *p_in = (char *) ∈ 
  char *p_out = (char *) &out; 
  p_out[0] = p_in[3]; 
  p_out[1] = p_in[2]; 
  p_out[2] = p_in[1]; 
  p_out[3] = p_in[0];   
  return out; 
}

- Omprakash April 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

union { uint8 nBytes[2]; uint16 hBytes; } DATA;
uint16 htons(uint16 hostBytes) {
DATA d.hBytes = hostBytes;
d.nBytes[0]=((hostBytes >>8) &0xFF);
d.nBytes[1]=((hostBytes & 0xFF)<<8)
return d.nBytes[0] | d.nBytes[1];
}

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

union { uint8 nBytes[2]; uint16 hBytes; } DATA;
uint16 htons(uint16 hostBytes) {
DATA d.hBytes = hostBytes;
uint8 temp [2]= {nBytes[1],nBytes[0]};
return *((uint16*)&temp[0]);
}

- akm April 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

int main()
{
 int x=0x12345678,final=0x0000,i;
int mask=0x000f,num=28;
int common;
for(i=0;i<8;i++)
{
common=x&mask;
x=x>>4;
final=final|(common<<num);
common=common<<(32-num);
num=num-4;
}
printf("final=%x",final);

return 0;
}

- uday September 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef union data
{
struct databyte{
char a;
char b;
char c;
char d;
} h;
int e;
};
int LittletoBigUnion(int g )
{
union data f;
f.e=g;
f.e=((f.h.a)<<24)|((f.h.b)<<16)|((f.h.c)<<8)|((f.h.d));
return f.e;
}
int LittletoBig(int a )
{
int b= ((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|((a&0xff000000)>>24);
return b;
}

- Anonymous December 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

typedef union data
{
struct databyte{
char a;
char b;
char c;
char d;
} h;
int e;
};
int LittletoBigUnion(int g )
{
union data f;
f.e=g;
f.e=((f.h.a)<<24)|((f.h.b)<<16)|((f.h.c)<<8)|((f.h.d));
return f.e;
}
int LittletoBig(int a )
{
int b= ((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|((a&0xff000000)>>24);
return b;
}

- Anonymous December 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

does this suffice ? not sure.

union { uint8 nBytes[2]; uint16 hBytes; } DATA;
uint16 htons(uint16 hostBytes) {
	DATA d.hBytes = hostBytes;
	return d.nBytes[1] | d.nBytes[0];
}

- VJ April 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

You need

(d.nBytes[1] << 8) | d.nBytes[0]

- eugene.yarovoi April 24, 2013 | 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