Discussion
Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.
Answer: A
Correct answer: Yes
This is the standard idiom for clearing bits. ~ inverts a mask so that the positions of interest hold 0 and everything else holds 1; AND then forces those positions to 0 and leaves the rest untouched.
So n &= ~0x02 clears bit 1, and n &= ~(0x02 | 0x08) clears two bits at once - the technique extends to as many as the mask names. It is the exact counterpart of n |= mask for setting bits, and the pair covers most bit manipulation in practice.
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