Data Structures & AlgorithmsModerateAmazon · Microsoft OA

Problem: A permissions engine isolates bits of a mask.

Problem: A permissions engine isolates bits of a mask.
x = 88
print(x & -x, x & (x - 1))
What is printed?
  1. A. 8 87
  2. B. 8 80
  3. C. 16 80
  4. D. 1 80

Correct answer: B. 8 80

88 = 1011000₂. x & −x keeps only the lowest set bit (1000₂ = 8), and x & (x − 1) clears that bit, leaving 1010000₂ = 80. Both rely on two's complement: −x = ~x + 1.

More Coding Interview Problems questions

Exams that ask this topic