ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print((-5).to_bytes(2, 'big', signed=True).hex(), int.from_bytes(b'\xff\xfb', 'big', signed=True), int.from_bytes(b'\xff\xfb', 'big'))
- A. fbff -5 65531
- B. fffb 5 65532
- C. fffb -5 -5
- D. fffb -5 65531
Correct answer: D. fffb -5 65531
Negative numbers are stored in two's complement, so -5 in two bytes is 0xfffb. Reading the same bytes as signed gives -5, and reading them as unsigned gives 65531.
More Python Programming questions
- What is printed? python import math print(math.fsum([0.1] 10) == 1.0, sum([0.1] 10) == 1.0, math.isqrt(10 30 - 1))
- What is printed? python print(sorted(['pear', 'Fig', 'apple', 'banana', 'kiwi'], key=lambda s: (len(s), s.lower())))
- What is printed? python print(sorted([('b', 1), ('a', 1), ('c', 2)], key=lambda t: t[1], reverse=True))
- What is printed? python print(max(['abc', 'x', 'yz'], key=len), min(['b', 'B', 'a']))
- What is printed? python from decimal import Decimal from fractions import Fraction print(0.1 + 0.2 == 0.3, Decimal('0.1') + Decimal('0.2')…
- What is printed? python print(1e22, 1e21, 1e16, 1e15, 1e-5, 0.0001)