ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(bin(-8 & 0xFF), (-8) >> 1, (-8) // 2, (-9) // 2, -9 >> 1)
- A. 0b11111000 -4 -4 -5 -5
- B. 0b11111000 -4 -4 -4 -5
- C. 0b1000 -4 -4 -5 -5
- D. 0b11111000 -3 -4 -5 -5
Correct answer: A. 0b11111000 -4 -4 -5 -5
-8 & 0xFF keeps the low eight bits, 11111000. Right shift and floor division both round toward minus infinity, so -9 >> 1 and -9 // 2 are both -5.
More Python Programming questions
- What is printed? python print(x := 7, x 2, [y := 3, y + 1])
- What is printed? python print('%s|%r' % ("it's", "it's"))
- What is printed? python print(ord('a') - ord('A'), chr(ord('A') + 32), 'Z'.lower() < 'a', 'z' > 'Z')
- What is printed? python print('-'.join('abc'), ''.join(map(str, [1, 2, 3])) == '123', ','.join([]) == '', 'x'.join(['', '']))
- What is printed? python s = 'hello' print(s.find('l'), s.index('l', 3), s.rfind('l'), s.count('ll'), s.find('z'))
- What is printed? python print('%.2e' % 0.000123456, '%G' % 1e-5, '%g' % 1e-5, '%.3g' % 1234.5)