ProgrammingHardTCS NQT · Wipro

What is the position of the lowest set bit of 0x0300 (counting bit 0 as position 0)? Compute with this program.

What is the position of the lowest set bit of 0x0300 (counting bit 0 as position 0)? Compute with this program.
#include <stdio.h>
int main(void) {
    unsigned x = 0x0300, p = 0;
    while (!(x & 1u)) { x >>= 1; p++; }
    printf("%u", p);
}
  1. A. 9
  2. B. 2
  3. C. 7
  4. D. 8

Correct answer: D. 8

0x0300 = 11 0000 0000 in binary, so its lowest set bit is bit 8.

More C Programming questions

Exams that ask this topic