ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(bin(0b1011011).count('1'), (0b1011011).bit_count(), 0b1011011 & (0b1011011 - 1))- A. 5 5 90
- B. 5 5 88
- C. 4 5 90
- D. 5 4 90
Correct answer: A. 5 5 90
Both ways of counting bits give 5 set bits in 1011011. Clearing the lowest set bit of 91 leaves 90, because the lowest set bit is the 1 in the units place.
More Python Programming questions
- What is printed? python def f(n): c = 0 while n: n &= n - 1 c += 1 return c print(f(255), f(-1 & 0xFF), f(0))
- What is printed? python s = 'abc' print(s[::-1] + s[0], s[1:] + s[:1], s[-1] + s[-2:])
- What is printed? python print(len('é'), len('é'.encode()), len(f'{"é":>3}'), len(str(0.1 + 0.2)))
- What is printed? python print('%-6s|' % 'ab', '%6.2f|' % 3.14159, '%+.1e' % 12345.6789)
- What is printed? python from decimal import Decimal, ROUNDHALFEVEN print(Decimal('2.5').quantize(Decimal('1'), rounding=ROUNDHALFEVEN)…
- What is printed? python x = 'a,b;c' print(x.split(',', 1), x.split(';')[0].split(','), [t for t in x.replace(';', ',').split(',') if t]…