ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(bin(6 & -6), bin(6 | -6), bin(6 ^ -6))
- A. 0b10 -0b110 -0b100
- B. 0b10 -0b10 -0b10
- C. 0b110 -0b10 -0b100
- D. 0b10 -0b10 -0b100
Correct answer: D. 0b10 -0b10 -0b100
6 & -6 isolates the lowest set bit, which is 2 (0b10). 6 | -6 is -2, and 6 ^ -6 is -4 in two's complement terms.
More Python Programming questions
- What is printed? python print(hex(28 - 1), oct(29), bin(24))
- What is printed? python print(str(0.5), str(0.25 + 0.125), 0.1 + 0.25)
- What is printed? python s = 'a,b;c' print(s.split(',;'), s.replace(';', ','), s.split(';'))
- What is printed? python print(max(range(5), key=lambda i: (i % 3, -i)))
- What is printed? python print(sum(x x for x in range(-3, 4)), sum(abs(x) for x in range(-3, 4)))
- What is printed? python print(2 0.5 2 0.5 == 2, round(2 0.5 2 0.5, 12) == 2)