Question DSA-BIT-0006
EasyHow can you check whether an integer n is odd using bits?
- A.
n ^ n == 1
- B.
n & 1 == 1
- C.
Show answer and explanation
Answer: B
The lowest bit is 1 exactly for odd numbers.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Bit Manipulation question
How can you check whether an integer n is odd using bits?
n ^ n == 1
n & 1 == 1
Answer: B
The lowest bit is 1 exactly for odd numbers.
n >> 1 == 1
n | 1 == 0