ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(-(-2**31) // 1, (2**31 - 1) & -(2**31), 2**31 >> 31, 2**32 & -2**32)
  1. A. 2147483647 0 1 4294967296
  2. B. 2147483648 -1 1 4294967296
  3. C. 2147483648 0 1 4294967296
  4. D. 2147483648 0 0 4294967296

Correct answer: C. 2147483648 0 1 4294967296

Unary minus binds tighter than **, so -(-2**31) is 2**31. The mask (2**31 - 1) & -(2**31) has no bits in common, so it is 0. 2**32 & -2**32 isolates the single bit 2**32.

More Python Programming questions

Exams that ask this topic