Bitfield mask/operations with optional items
- by user1560249
I'm trying to find a way to handle several bitfield cases that include optional, required, and not allowed positions.
yy?nnn?y
11000001
?yyy?nnn
01110000
nn?yyy?n
00011100
?nnn?yyy
00000111
In these four cases, the ? indicates that the bit can be either 1 or 0 while y indicates a 1 is required and n indicates that a 0 is required. The bits to the left/right of the required bits can be anything and the remaining bits must be 0. Is there a masking method I can use to test if an input bit set satisfies one of these cases?