ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(bin(-8 & 0xFF), (-8) >> 1, (-8) // 2, (-9) // 2, -9 >> 1)
  1. A. 0b11111000 -4 -4 -5 -5
  2. B. 0b11111000 -4 -4 -4 -5
  3. C. 0b1000 -4 -4 -5 -5
  4. D. 0b11111000 -3 -4 -5 -5

Correct answer: A. 0b11111000 -4 -4 -5 -5

-8 & 0xFF keeps the low eight bits, 11111000. Right shift and floor division both round toward minus infinity, so -9 >> 1 and -9 // 2 are both -5.

More Python Programming questions

Exams that ask this topic