ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
x = 0b1011 print(bin(x << 3), bin(x >> 1), x << 3 >> 3 == x, bin(~x & 0b1111))
- A. 0b1011000 0b101 True 0b100
- B. 0b1011000 0b101 False 0b100
- C. 0b1011000 0b101 True 0b1011
- D. 0b101100 0b101 True 0b100
Correct answer: A. 0b1011000 0b101 True 0b100
Shifting left by 3 appends three zeros, and shifting right by 1 drops the last bit. Shifting back restores x, and ~x & 0b1111 gives the four-bit complement 0100.
More Python Programming questions
- What is printed? python print(3 'ab' == 'ab' 3, 'ab' 3 == 'aba' + 'bab', [0] 3 == [0, 0, 0], ['a'] 2 == 'aa')
- What is printed? python s = 'The Quick' print(s.lower().split(), s.split('Q')[0].strip(), s[s.index(' ') + 1:], s.title().swapcase())
- What is printed? python print('%d items at %.1f%%' % (3, 12.345), '%5.2f|' % -1.005, '%08.3f' % -3.14159)
- What is printed? python print(int('12') 2 3, float('12e3') // 1000, float('1000.5e1'))
- What is printed? python import math print(math.gcd(-12, 18), math.gcd(12, -18), math.lcm(-4, 6), math.gcd(0, 0))
- What is printed? python def digitssum(n): return sum(int(c) for c in str(abs(n))) print(digitssum(-9075), digitssum(1020), digitssum(0))