ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(bin(-5), format(-5, '08b'), (-5) & 0xFF, format(-5 & 0xFF, '08b'))
- A. -0b101 -0000101 -5 11111011
- B. -0b101 -0000101 251 11111011
- C. 0b11111011 -0000101 251 11111011
- D. -0b101 -0000101 251 00000101
Correct answer: B. -0b101 -0000101 251 11111011
bin() of a negative int puts the minus sign in front of the magnitude rather than printing two's complement. Masking with 0xFF exposes the 8-bit two's complement pattern 11111011, which is 251.
More Python Programming questions
- What is printed? python print(divmod(-17, 5), divmod(17, -5), divmod(-17.0, 5))
- What is printed? python print(7 // -2, -7 // 2, 7.0 // -2, -7.0 % 2)
- What is printed? python print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))
- What is printed? python print(sum([0.1] 10) == 1.0, sum([0.1] 10), sum([0.1] 10, 0) == 1.0)
- What is printed? python print(int(3.9999999999999999), int(-3.7), round(-3.7))
- What is printed? python print(hash(1) == hash(1.0), hash(True) == 1, {1: 'a', 1.0: 'b', True: 'c'})