ProgrammingVery hardProduct-company MCQ pattern

What is printed?

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

Correct answer: A. 1 -1 -2 8

In two's complement -7 is ...11001. 7 & -7 keeps only the lowest set bit, 1, and 7 | -7 sets every bit of the low three positions, giving -1. ~7 is -8, and -8 & 15 is 8.

More Python Programming questions

Exams that ask this topic