I wanted to track some options via bitmask’ing them, and borrowed bitmask values from this answer, yet they not seem to work together.
#include <iostream>
#define OP1 0x00003FFFUL
#define OP2 0x00007FFFUL
#define OP3 0x0000FFFFUL
int main() {
unsigned long params = 0; // .
params |= OP3;
if ( (params & OP1) == OP1)
std::cout << "Whoa. Lame masking\n";
}
Is it a type problem, or this method can’t be used for holding more than 1 option at a time (both OP1, OP2 and OP3 are wanted to stay in same params)?
For options you should use other masks, ones that are not overlapped, such as:
or (in this case you’ll be able to store as many options as available bits):
Your masks will never work properly because if OP3 is set then OP1 and OP2 will be contained (the same goes if you use OP2, then OP1 will be implied):
The masks in the example you pasted were intended to extrapolate the last bits of an UL.