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);
}
  1. A. 3
  2. B. 2
  3. C. 1
  4. 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

Exams that ask this topic