Question DSA-BIT-0050
MediumHow do you toggle the k-th bit of n (0-indexed)?
- A.
n ^ (1 << k)
- B.
n & ~(1 << k)
- C.
n >> k
- D.
n | (1 << k)
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Bit Manipulation question
How do you toggle the k-th bit of n (0-indexed)?
n ^ (1 << k)
n & ~(1 << k)
n >> k
n | (1 << k)
Sign up free to see the answer and a step-by-step explanation.