ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: B. 4 8 3

12 & -12 isolates the lowest set bit of 12, which is 4. 12 & 11 keeps the common bits 1000, which is 8. ~12 is -13, and its low four bits are 0011, which is 3.

More Python Programming questions

Exams that ask this topic