ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
x = 0b1011
print(bin(x << 3), bin(x >> 1), x << 3 >> 3 == x, bin(~x & 0b1111))
  1. A. 0b1011000 0b101 True 0b100
  2. B. 0b1011000 0b101 False 0b100
  3. C. 0b1011000 0b101 True 0b1011
  4. D. 0b101100 0b101 True 0b100

Correct answer: A. 0b1011000 0b101 True 0b100

Shifting left by 3 appends three zeros, and shifting right by 1 drops the last bit. Shifting back restores x, and ~x & 0b1111 gives the four-bit complement 0100.

More Python Programming questions

Exams that ask this topic