ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print((1 << 70).bit_count(), (2**70 - 1).bit_count(), (-1).bit_count(), (-8).bit_count())
  1. A. 1 70 -1 -8
  2. B. 1 70 1 0
  3. C. 1 69 1 1
  4. D. 1 70 1 1

Correct answer: D. 1 70 1 1

int.bit_count() counts the set bits of the absolute value, so it works on negatives too. 2**70 - 1 has seventy one-bits, and -1 and -8 each have one set bit in their absolute values.

More Python Programming questions

Exams that ask this topic