ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
x = 2 ** 63
print(x.bit_length(), (x - 1).bit_length(), x >> 62, (-1) >> 100, 1 << 0, (5).to_bytes(2, "big"))
  1. A. 64 64 2 0 1 b'\x00\x05'
  2. B. 63 63 2 -1 1 b'\x05\x00'
  3. C. 64 63 2 -1 0 b'\x00\x05'
  4. D. 64 63 2 -1 1 b'\x00\x05'

Correct answer: D. 64 63 2 -1 1 b'\x00\x05'

2^63 needs 64 bits, while 2^63 - 1 needs 63. Right-shifting a negative number floors, so -1 stays -1 no matter how far it is shifted. to_bytes with 'big' puts the most significant byte first.

More Python Programming questions

Exams that ask this topic