ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
x = 255
print(x.to_bytes(2, 'little'), int.from_bytes(b'\x01\x02', 'little'), (258).to_bytes(2, 'big').hex())
  1. A. b'ff00' 513 0201
  2. B. b'\xff\x00' 258 0102
  3. C. b'\xff\x00' 513 0102
  4. D. b'\xff\x00' 513 0201

Correct answer: C. b'\xff\x00' 513 0102

Little-endian puts the low byte first, so 255 becomes b'\xff\x00'. Reading bytes 01 02 little-endian gives 0x0201, which is 513, and 258 is 0x0102 in big-endian hex.

More Python Programming questions

Exams that ask this topic