ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print((-5).to_bytes(2, 'big', signed=True).hex(), int.from_bytes(b'\xff\xfb', 'big', signed=True), int.from_bytes(b'\xff\xfb', 'big'))
  1. A. fbff -5 65531
  2. B. fffb 5 65532
  3. C. fffb -5 -5
  4. D. fffb -5 65531

Correct answer: D. fffb -5 65531

Negative numbers are stored in two's complement, so -5 in two bytes is 0xfffb. Reading the same bytes as signed gives -5, and reading them as unsigned gives 65531.

More Python Programming questions

Exams that ask this topic