ProgrammingHardCompetitive coding (CP)
How many trailing one bits does 0x1F3 have? Compute with this program.
How many trailing one bits does 0x1F3 have? Compute with this program.
#include <stdio.h>
int main(void) {
unsigned x = 0x1F3;
int c = 0;
while (x & 1u) {
x >>= 1;
c++;
}
printf("%d", c);
}- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
0x1F3 ends in binary ...110011, so the loop shifts out the two low ones and then stops at a zero bit. The count is 2.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned long long p = 0xFFFFu 0xFFFFu; printf("%llu", p); }
- What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f. c #include <stdio.h> void f(char s[]) {…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 2 3 + 4 % 3 == 0 ? 1 : 2); }
- What is printed? Assume a 32-bit unsigned int. c #include <stdio.h> int main(void) { unsigned x = 1; for (int i = 0; i < 31; i++) x <<= 1…
- What is printed? c #include <stdio.h> int main(void) { int i; int a[5] = {0}; for (i = 0; i < 5; i++) a[i] = i i; printf("%d", a[4]…
- How many placements of 4 queens on a 4 by 4 board have no two queens attacking each other? The program counts them by backtracking. What…