ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
n = 0b10110000
print(n & -n, n & (n - 1), bin(n >> 4), n.bit_count())
  1. A. 16 160 0b1011 4
  2. B. 16 160 0b1011 3
  3. C. 16 160 0b1100 3
  4. D. 16 96 0b1011 3

Correct answer: B. 16 160 0b1011 3

n & -n isolates the lowest set bit (16), and n & (n - 1) clears it to give 160. The value 176 has three set bits and shifts right by four to 0b1011.

More Python Programming questions

Exams that ask this topic