ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(bin(10)[2:].zfill(8), format(-10, '08b'), format(-10 & 0xFF, '08b'), f'{255:#x}')
  1. A. 00001010 -0001010 11110110 0xff
  2. B. 00001010 -00001010 11110110 0xff
  3. C. 1010 -0001010 11110110 0xFF
  4. D. 00001010 -0001010 11110110 255

Correct answer: A. 00001010 -0001010 11110110 0xff

The 08b spec pads to width 8 with the sign counted, so -10 becomes -0001010. Masking with 0xFF gives the 8-bit two's complement pattern 11110110, and #x adds a lowercase 0x prefix.

More Python Programming questions

Exams that ask this topic