ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(7 & -8, 7 | -8, 7 ^ -8, ~7 & 0xFF)
- A. 7 -1 -1 248
- B. 0 -1 -1 248
- C. 0 -1 -1 8
- D. 0 -1 -1 240
Correct answer: B. 0 -1 -1 248
-8 has all high bits set and its low three bits are 000, so 7 & -8 is 0. Both 7 | -8 and 7 ^ -8 end in all ones, which is -1. ~7 is -8, and -8 & 0xFF is 248.
More Python Programming questions
- What is printed? python print(float(' 1000.5 '), float('infinity') > 1e308, float('-nan') != float('-nan'), int(' +0012 '))
- What is printed? python print(b'abc'[0], bytes([65, 66]), bytes.fromhex('41 42'), len(b'a' 2 + b'x00'))
- What is printed? python print(sorted(['b', 'A', 'c', 'B'], key=str.casefold, reverse=True))
- What is printed? python try: print(sorted([3, None, 1])) except TypeError: print('cannot compare')
- What is printed? python print('%(a)s-%(b)05.1f' % {'a': 'x', 'b': 3.14159})
- What is printed? python s = 'Ünïcödé' print(len(s), len(s.encode()), s.upper() == 'ÜNÏCÖDÉ')