I have
#define MS 0x0100|0x011
I need to check 0x011 present in MS. I use MS & 0x011
which is giving value present. But id MS & 0x10
also giving true value, I need it as false
CodePudding user response:
(value & mask) != 0
: is at least one of the setmask
bits also set invalue
?
(This is whatvalue & mask
is in a boolean context.)(value & mask) == mask
: are all the setmask
bits also set invalue
?
That is, the first is like "or" and the second like "and".
CodePudding user response:
(Edited) You need
((MS) & 0x11) == 0x11
Thanks to lorro for his comment
CodePudding user response:
The 0x0100 | 0x011
will result in 0x111
which will result in all &
tests for 0x1, 0x10, 0x100, 0x11, 0x110 and 0x111
to evaluate true
.
You need to test your values directly, and will not be able to use your #define
.