ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(bin(5 << 2), 5 >> 1, -5 >> 1, -5 // 2)
  1. A. 0b10100 2 -3 -2
  2. B. 0b1010 2 -3 -3
  3. C. 0b10100 2 -3 -3
  4. D. 0b10100 2 -2 -3

Correct answer: C. 0b10100 2 -3 -3

5 << 2 is 20, which is 0b10100. >> is an arithmetic shift, so -5 >> 1 floors to -3, the same as -5 // 2.

More Python Programming questions

Exams that ask this topic