Samsung Interview Question for Developer Program Engineers






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

number of bits, simple solution:

int n = 0;
while (x) {
  if (x & 0x1) n++;
  x >>= 1;
}

faster solution (hint from k&r - study difference between x and x - 1)

int n = 0;
while (x) {
  x = x & ~(x ^ (x-1));
  n++;
}

- petra November 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

even faster version:

{
 char a[16]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}
return(a[num&0xff000000>>24]+a[num&0xff0000>>16]+a[num&0xff00>>8]+a[num&ff]);
}

- Charles December 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define getsize(x) ((char *)(&(x) + 1) - (char *)&(x))
int i; getsize(i);



char *strcpy(char *dest, const char *src){
char *save = dest;
while(*dest++ = *src++);
return save;}


Structure padding is adding extra bits at the end of the structue,so that the structure completes the word boundary. Structure padding is used to pad the data in such a way that it can be sent to external devices. Sometimes, the data is padded in such a way that it can be used on little endian vs big endian processors .

- aditya.bokaro August 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

To find the number of bits set in a number:

while(num !=0)
num &= num - 1;

Best sol, will run only for the no. Of bits set in the no.

- ankit.batra11 April 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int dig,num_bit=0;
while(dig)
{
num_bit++;
dig = dig>>1;
}

- Shashank Dixit July 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.


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