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)
- A. 2147483647 0 1 4294967296
- B. 2147483648 -1 1 4294967296
- C. 2147483648 0 1 4294967296
- 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
- What is printed? python print((1 << 3) - 1 << 2, 1 << 3 - 1 << 2, 1 + 2 << 1, 3 & 2 2)
- What is printed? python print(0 0, 0.0 0, (-8) 0, (-2) 3, -2 3)
- What is printed on the first line? python print(sorted(['10', '9', '2'], key=int)) print(sorted(['10', '9', '2'])) print(sorted(['a', 'B'…
- What is printed? python print('a' 'b' 2, ('a' 'b') 2, 'ab' 0 == '', 'x' 3 + 'y' 2)
- What is printed? python print('%.2f' % 2.675, '%.2f' % 2.665, round(2.665, 2), format(2.5, '.0f'), format(0.125, '.2f'))
- What is printed? python print(0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6, 0.1 + (0.2 + 0.3) == 0.6)