ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(-6 & 0xFF, -6 | 3, -6 ^ -3, ~-6 >> 1)
  1. A. 250 -1 7 2
  2. B. 250 -5 7 3
  3. C. -6 -5 7 2
  4. D. 250 -5 7 2

Correct answer: D. 250 -5 7 2

Python ints behave as infinite two's complement, so -6 & 0xFF keeps the low byte 250. -6 | 3 is -5, -6 ^ -3 is 7, and ~-6 is 5, so 5 >> 1 = 2.

More Python Programming questions

Exams that ask this topic