Discussion
Which bitwise operator is suitable for turning off a particular bit in a number?
Answer: B
Correct answer: & operator
Turning a bit off means forcing it to 0 while leaving the others untouched, and only AND can do that: \( b \mathbin{\&} 0 = 0 \) for any \( b \), while \( b \mathbin{\&} 1 = b \).
The idiom is therefore n &= ~(1 << k) - build a mask with a single 1 in position \( k \), invert it so that position alone is 0, and AND. && and || are logical operators yielding only 0 or 1 and destroying the other bits entirely; ! is logical negation of the whole value.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development