ProgrammingHardTCS NQT · Wipro
How many set bits does this loop count in 0xFFFF0000?
How many set bits does this loop count in 0xFFFF0000?
#include <stdio.h>
int main(void) {
unsigned x = 0xFFFF0000u;
int c = 0;
while (x) { c += x & 1u; x >>= 1; }
printf("%d", c);
}- A. 32
- B. 16
- C. 8
- D. 15
Correct answer: B. 16
The upper sixteen bits are all set and the lower sixteen are clear, so the count is 16.
More C Programming questions
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned a = 65536u; printf("%u", a a); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", sizeof(char) - 2 > 0); }
- What is printed? c #include <stdio.h> int main(void) { int a[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; int best = a[0], cur = a[0]; for (int i…
- How many subarrays of {1, -1, 2, -2, 3} have sum zero? Compute with this program. c #include <stdio.h> int main(void) { int a[] = {1, -1…
- What is printed? c #include <stdio.h> int pc(unsigned n) { return n ? (int)(n & 1u) + pc(n >> 1) : 0; } int main(void) { printf("%d"…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (13 << 1) + 13); }