ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
n = 0b10110000 print(n & -n, n & (n - 1), bin(n >> 4), n.bit_count())
- A. 16 160 0b1011 4
- B. 16 160 0b1011 3
- C. 16 160 0b1100 3
- D. 16 96 0b1011 3
Correct answer: B. 16 160 0b1011 3
n & -n isolates the lowest set bit (16), and n & (n - 1) clears it to give 160. The value 176 has three set bits and shifts right by four to 0b1011.
More Python Programming questions
- What is printed? python a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b, a ^ b)
- What is printed? python print(0xFF >> 4 << 4 == 0xF0, 1 << 63 > 0, (1 << 63) - 1 == 263 - 1, -(1 << 63) >> 63)
- What is printed on the third line? python names = ['bob', 'Alice', 'carl', 'Bob', 'alice'] print(sorted(names)) print(sorted(names…
- What is printed? python x = 253 print(float(x + 1) == x, x + 1.0 == x, (x + 2.0) - x, int(float(x + 3)) - x)
- What is printed? python print([10, 20, 30][True], (5).bitlength(), (True).bitlength(), (-1).bitlength())
- What is printed? python print(round(7.5), round(6.5), round(-7.5), round(7.5000001))