Discussion
Bitwise & can be used to check if more than one bit in a number is on.
Answer: A
Correct answer: True
AND with a mask isolates exactly the bits the mask selects, and a mask may name as many positions as wanted. To test whether any of several bits is set, OR the masks together and AND once: if (n & (BIT2 | BIT5)) is true if either is on.
Testing that all of them are on needs a comparison rather than a mere test: if ((n & mask) == mask). That distinction - non-zero means at least one, equality means all - is the practical point behind the question.
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