QUALCOMM Interview Question
308 Interview Reviews |
Back to all QUALCOMM Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Senior Software Engineer at QUALCOMM:
Write a C function to return the number of set bits in an integer.
See more for this QUALCOMM Senior Software Engineer Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (2)
0, /* 0x0, b0000 */
1, /* 0x1, b0001 */
1, /* 0x2, b0010 */
2, /* 0x3, b0011 */
1, /* 0x4, b0100 */
2, /* 0x5, b0101 */
2, /* 0x6, b0110 */
3 /* 0x7, b0111 */
1 /* 0x8, b1000 */
2 /* 0x9, b1001 */
2 /* 0xA, b1010 */
3 /* 0xB, b1011 */
2 /* 0xC, b1100 */
3 /* 0xD, b1101 */
3 /* 0xE, b1110 */
4 /* 0xF, b1111 */
};
#define NumBytesInInt 4 /* assumes 32bit system */
int GetNumberOfSetBits(int anInteger)
{
uint8_t buf[NumBytesInInt ];
int i;
int count = 0;
memcpy(buf, &anInteger, sizeof(buf));
for (i=0; i<NumBytesInInt; ++i) {
count += NumberOfSetBits[buf[i] &0x0F];
count += NumberOfSetBits[buf[i] >> 4];
}
return count;
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 6 people found this helpful
by Brad Murry: