Question 1
EasyWhat is 5 & 3?
- A.
6
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 5 & 3?
6
1
8
7
Answer: B
0101 AND 0011 = 0001, which is 1.
What is 5 | 3?
1
6
8
7
Answer: D
0101 OR 0011 = 0111, which is 7.
What is 5 ^ 3?
8
1
6
7
Answer: C
0101 XOR 0011 = 0110, which is 6.
What is 1 << 4?
8
4
5
16
Answer: D
Shifting left by 4 multiplies by 2⁴ = 16.
What is 32 >> 2?
8
16
128
30
Answer: A
Shifting right by 2 divides by 2² = 4: 32 / 4 = 8.
How can you check whether an integer n is odd using bits?
n ^ n == 1
n & 1 == 1
n >> 1 == 1
n | 1 == 0
Answer: B
The lowest bit is 1 exactly for odd numbers.
What is x ^ x for any integer x?
2x
x
0
1
Answer: C
Every bit is XORed with itself, giving 0.
What is 12 written in binary?
1110
1010
1100
0110
Answer: C
12 = 8 + 4, so the bits for 8 and 4 are 1 and the bits for 2 and 1 are 0: 1100₂.
What is the binary number 1011 in decimal?
13
11
1011
9
Answer: B
1 × 8 + 0 × 4 + 1 × 2 + 1 × 1 = 11.
How many 1 bits are there in the binary form of 13?
3
4
1
2
Answer: A
13 = 1101₂, which has three 1s.