ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
x = 0 x |= 1 << 3 x &= ~(1 << 0) x ^= 0b111 print(x, x.bit_count(), (x >> 1) & -x)
- A. 15 3 1
- B. 15 4 1
- C. 15 4 7
- D. 8 4 1
Correct answer: B. 15 4 1
x becomes 8, then ~1 clears nothing, and XOR with 7 gives 15, which has four set bits. (15 >> 1) & -15 isolates the lowest set bit of 7, which is 1.
More Python Programming questions
- What is printed? python print(-(-231) // 1, (231 - 1) & -(231), 231 >> 31, 232 & -232)
- 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'))