ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 & -7, 7 | -7, 7 ^ -7, ~7 & 0xF)
- A. 1 -1 -2 8
- B. 1 -1 -2 9
- C. 1 -1 -3 8
- D. 2 -1 -2 8
Correct answer: A. 1 -1 -2 8
In two's complement -7 is ...11001. 7 & -7 keeps only the lowest set bit, 1, and 7 | -7 sets every bit of the low three positions, giving -1. ~7 is -8, and -8 & 15 is 8.
More Python Programming questions
- What is printed? python print(bin(5 & -5), (5).bitcount(), (-5).bitcount(), (-5).bitlength())
- What is printed? python print(0b1 << 100 > 299, (1 << 100).bitlength(), len(bin(1 << 100)) - 2)
- What is printed? python print(float(3) / 2 == 1.5, 3 // 2.0, 3 / 2.0 // 1)
- What is printed? python print(round(3.14159, 3), round(2.5e-7, 7), round(123.456, -1), round(-0.0001, 2))
- What is printed? python print('Hello World'.swapcase().title(), 'tEST'.capitalize(), 'x'.isalpha(), '1.5'.isdigit(), '١٢'.isdigit())
- What is printed? python print('ab' in 'cabd', '' in 'abc', 'abc'.index(''), len('abc'[3:]), len('abc'[4:]))