ProgrammingHardCodeforces-style · placement coding round

What is printed?

What is printed?
x = 0b101100
print(x & (x - 1), x & -x, bin(x).count('1'))
  1. A. 40 4 3
  2. B. 43 4 3
  3. C. 40 8 3
  4. D. 40 4 2

Correct answer: A. 40 4 3

x & (x-1) clears the lowest set bit, x & -x isolates it, and bin(x).count('1') counts set bits. For 44 = 101100 these give 40, 4 and 3.

More Python Programming questions

Exams that ask this topic