ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(bin(5 ^ 3), bin(-5 & 0b1111), int('-0b101', 2))
  1. A. 0b110 0b1011 -5
  2. B. 0b110 0b1011 -6
  3. C. 0b110 0b1111 -5
  4. D. 0b101 0b1011 -5

Correct answer: A. 0b110 0b1011 -5

5 xor 3 is 6, which is 0b110. -5 in four bits is 1011, and int() accepts a sign before a prefix that matches the base, so the result is -5.

More Python Programming questions

Exams that ask this topic