ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f'{-5:x}', f'{-5 & 0xF:x}', hex(-255), format(255, '#010b'))
  1. A. -5 b 0xfe 0b11111111
  2. B. -5 b -0xff 0b11111111
  3. C. -5 11 -0xff 0b11111111
  4. D. -5 b -0xff 0b1111

Correct answer: B. -5 b -0xff 0b11111111

Hex format on a negative number keeps the minus sign, and -5 & 0xF is 11, which is b. hex(-255) is -0xff, and #010b pads the binary digits so the whole result is ten characters with the 0b prefix.

More Python Programming questions

Exams that ask this topic