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.
Please log in or register to report this question.