ProgrammingVery hard

The lowest bit that is zero in x = 0b1011 is isolated by ~x & (x + 1). What value does this give?

  1. A. 8
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: C. 4

x + 1 is 12, and ~x has zeros where x has ones. The AND gives 0b100, which is 4, the first zero bit above the trailing ones.

More C Programming questions

Exams that ask this topic