ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(bin(-5), format(-5, '08b'), (-5) & 0xFF, format(-5 & 0xFF, '08b'))
  1. A. -0b101 -0000101 -5 11111011
  2. B. -0b101 -0000101 251 11111011
  3. C. 0b11111011 -0000101 251 11111011
  4. D. -0b101 -0000101 251 00000101

Correct answer: B. -0b101 -0000101 251 11111011

bin() of a negative int puts the minus sign in front of the magnitude rather than printing two's complement. Masking with 0xFF exposes the 8-bit two's complement pattern 11111011, which is 251.

More Python Programming questions

Exams that ask this topic