Question 21
EasyWhat is the output of this code?
print(bin(10))
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the output of this code?
print(bin(10))
0b1100
0b1010
10
1010
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print(bin(29).count('1'))
5
3
29
4
Sign up free to see the answer and a step-by-step explanation.
In [4, 1, 2, 1, 2], every number appears twice except one. What does XOR-ing all the elements give?
0
1
10
4
Sign up free to see the answer and a step-by-step explanation.
What is a bitmask?
An integer whose bits are used as a set of on/off flags
A mask worn by programmers
A type of encryption
A floating-point number
Sign up free to see the answer and a step-by-step explanation.
Every subset of 4 items is represented by a bitmask. How many different masks are there?
16
4
15
8
Sign up free to see the answer and a step-by-step explanation.
For a non-negative integer, what does a right shift by 1 (n >> 1) do?
Divides it by 2, dropping any remainder
Makes it negative
Adds 1
Multiplies it by 2
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
x = 0
x |= 1 << 2
x |= 1 << 0
print(x)
4
3
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
def power_of_two(n):
return n > 0 and n & (n - 1) == 0
print(power_of_two(16), power_of_two(18))
False False
False True
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
n, c = 13, 0
while n:
n &= n - 1
c += 1
print(c)
3
4
Sign up free to see the answer and a step-by-step explanation.
What does x & (−x) give in two's complement?
The lowest set bit of x
The highest set bit of x
−1
0
Sign up free to see the answer and a step-by-step explanation.
5
6
True False
True True
1
2