ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
x = 0xFF
print(x >> 4, x & 0xF0, x ^ 0x0F, ~x & 0xFF)
  1. A. 15 240 15 0
  2. B. 15 240 240 255
  3. C. 15 241 240 0
  4. D. 15 240 240 0

Correct answer: D. 15 240 240 0

Shifting 0xFF right by four gives 15, and the high nibble mask gives 240. XOR with 0x0F clears the low nibble to 240, and ~255 masked to a byte is 0.

More Python Programming questions

Exams that ask this topic