ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
x = 17
print(x.bit_length(), (x & -x).bit_length(), x.bit_count(), bin(x)[2:].zfill(8))
  1. A. 5 1 2 10001
  2. B. 5 2 2 00010001
  3. C. 5 1 2 00010001
  4. D. 4 1 2 00010001

Correct answer: C. 5 1 2 00010001

17 is 10001 in binary, so it needs five bits and has two set bits. Its lowest set bit is 1, which needs one bit, and zfill pads the eight-digit form with a leading zero.

More Python Programming questions

Exams that ask this topic