ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(7 & -8, 7 | -8, 7 ^ -8, ~7 & 0xFF)
  1. A. 7 -1 -1 248
  2. B. 0 -1 -1 248
  3. C. 0 -1 -1 8
  4. D. 0 -1 -1 240

Correct answer: B. 0 -1 -1 248

-8 has all high bits set and its low three bits are 000, so 7 & -8 is 0. Both 7 | -8 and 7 ^ -8 end in all ones, which is -1. ~7 is -8, and -8 & 0xFF is 248.

More Python Programming questions

Exams that ask this topic