ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(bin(-1 & 0b111), (-1) & 0xF == 15, -16 >> 2, -15 >> 2)
- A. 0b111 False -4 -4
- B. 0b111 True -4 -4
- C. 0b111 True -3 -4
- D. 0b11 True -4 -4
Correct answer: B. 0b111 True -4 -4
-1 has all bits set, so masking with 0b111 gives 7 (0b111). The & operator binds tighter than ==, and right shifts of negative ints floor, so -15 >> 2 is -4.
More Python Programming questions
- What is printed? python print(''.join(sorted(set('mississippi'))), ''.join(sorted('mississippi', key=lambda c: (-'mississippi'.count(c)…
- What is printed? python print(str(1.1 1.1), str(1.21), 1.1 1.1 == 1.21, abs(1.1 1.1 - 1.21) < 1e-12)
- What is printed? python print(10 2 == 100.0, 2 0.5 2 == 2 0.25, pow(4, 0.5))
- What does ','.join([1, 2]) do in Python 3?
- Which statement about the heapq module is correct?
- What is printed? python print(sum(range(1, 10 5 + 1, 7)))