ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
x = 2 ** 63 print(x.bit_length(), (x - 1).bit_length(), x >> 62, (-1) >> 100, 1 << 0, (5).to_bytes(2, "big"))
- A. 64 64 2 0 1 b'\x00\x05'
- B. 63 63 2 -1 1 b'\x05\x00'
- C. 64 63 2 -1 0 b'\x00\x05'
- D. 64 63 2 -1 1 b'\x00\x05'
Correct answer: D. 64 63 2 -1 1 b'\x00\x05'
2^63 needs 64 bits, while 2^63 - 1 needs 63. Right-shifting a negative number floors, so -1 stays -1 no matter how far it is shifted. to_bytes with 'big' puts the most significant byte first.
More Python Programming questions
- What is printed? python import math print(math.floor(-2.5), math.ceil(-2.5), math.trunc(-2.5), int(-2.5), round(-2.5), -2.5 // 1)
- What is printed? python print(3 "ab" == "ab" 3, [1] 3 is [1] 3, "%" in "100%", "100%%" % (), f"{{x}}")
- What is printed? python x = 10 s = f"{x=}, {x2=}, {x:04}, {'a' if x > 5 else 'b'}" print(s)
- What is printed? python def f(): yield 1 g = f() print(type(f).name, type(g).name, hasattr(g, "next"), iter(g) is g, callable(g))
- What is printed? python class Matrix: def init(self, r): self.r = r def getitem(self, idx): i, j = idx return self.r[i][j] def…
- What is printed? python a = [1, 2, 3] b = a[:] print(a == b, a is b, a[:] is a[:], id(a) == id(b), a.copy() == list(a))