ProgrammingHardGATE CS · Campus placements

For an unsigned integer x, which expression clears the lowest set bit of x?

  1. A. x | (x * 2)
  2. B. x ^ (x >> 3)
  3. C. x & (x - 1)
  4. D. x & (x - 4)

Correct answer: C. x & (x - 1)

x - 1 flips the lowest set bit to 0 and the zeros below it to 1, so ANDing with x clears exactly the lowest set bit. The other forms do not do this: x | (x * 2) sets bits and the subtract-4 form clears a different pattern.

More C Programming questions

Exams that ask this topic