ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(bin(6 & -6), bin(6 | -6), bin(6 ^ -6))
  1. A. 0b10 -0b110 -0b100
  2. B. 0b10 -0b10 -0b10
  3. C. 0b110 -0b10 -0b100
  4. D. 0b10 -0b10 -0b100

Correct answer: D. 0b10 -0b10 -0b100

6 & -6 isolates the lowest set bit, which is 2 (0b10). 6 | -6 is -2, and 6 ^ -6 is -4 in two's complement terms.

More Python Programming questions

Exams that ask this topic