ProgrammingVery hardJEE Main · CAT placement
What is printed?
What is printed?
n = 13 print(n ^ (n >> 1), [bin(i ^ (i >> 1)) for i in range(4)])
- A. 13 ['0b0', '0b1', '0b11', '0b10']
- B. 11 ['0b0', '0b1', '0b10', '0b11']
- C. 11 ['0b0', '0b1', '0b11', '0b10']
- D. 11 ['0b1', '0b1', '0b11', '0b10']
Correct answer: C. 11 ['0b0', '0b1', '0b11', '0b10']
x ^ (x >> 1) is the Gray code. For 13 (1101) it is 1101 ^ 0110 = 1011, which is 11. The first four Gray codes are 0, 1, 3 and 2.
More Python Programming questions
- What is printed? python print(~5 == -6, ~(-5) == 4, (-5) >> 1 == -2, -5 // 2 == -3)
- What is printed? python import unicodedata print(unicodedata.normalize('NFC', 'eu0301') == 'é', len(unicodedata.normalize('NFD', 'é'))…
- What is printed? python print('a1'.isalnum(), '١'.isalnum(), ' '.isspace(), ''.isspace(), 'u00a0'.isspace())
- What is printed? python def fermatinverse(a, p): return pow(a, p - 2, p) print(fermatinverse(3, 7) == pow(3, -1, 7), 3 fermatinverse(3, 7)…
- What is printed? python print(sorted(['beta', 'Alpha', 'alpha', 'Beta'], key=str.lower))
- What is printed? python x = 0.1 + 0.7 print(x, x 10, int(x 10), round(x 10))