Question 11
EasyWhat does n & (n − 1) do to an integer n?
- A.
It reverses the bits
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 does n & (n − 1) do to an integer n?
It reverses the bits
It clears the lowest set bit of n
It doubles n
It sets every bit of n
Sign up free to see the answer and a step-by-step explanation.
Which test checks whether a positive integer n is a power of two?
n % 2 == 1
n ^ n == 0
n >> 1 == 0
n & (n − 1) == 0
Sign up free to see the answer and a step-by-step explanation.
Which expression multiplies an integer n by 8?
n << 3
n ^ 8
n << 8
n >> 3
Sign up free to see the answer and a step-by-step explanation.
Compute 6 ^ 6 ^ 9 (^ is bitwise XOR).
15
6
0
9
Sign up free to see the answer and a step-by-step explanation.
Which expression toggles (flips) bit k of n (bits counted from 0)?
n ^ (1 << k)
n >> k
n | (1 << k)
n & (1 << k)
Sign up free to see the answer and a step-by-step explanation.
Which expression gives 1 if bit k of n is set and 0 otherwise?
n | k
n ^ k
n << k
(n >> k) & 1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a, b = 5, 9
a ^= b
b ^= a
a ^= b
print(a, b)
0 0
9 5
5 9
14 5
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print(~0)
255
-1
0
1
Sign up free to see the answer and a step-by-step explanation.
Compute the bitwise AND of 7 and 8.
1
15
56
0
Sign up free to see the answer and a step-by-step explanation.
How many bits are needed to represent 255 in unsigned binary?
7
8
9
255
Sign up free to see the answer and a step-by-step explanation.