Data Structures & AlgorithmsModerateTCS NQT · bit tricks

Problem: What does the expression 'x & (x - 1)' clear in the binary representation of x?

  1. A. The highest set bit
  2. B. All bits
  3. C. The lowest set bit
  4. D. The sign bit only

Correct answer: C. The lowest set bit

Subtracting 1 flips the trailing zeros and the lowest set bit, and the AND removes that lowest set bit.

More Coding Interview Problems questions

Exams that ask this topic