OK, so you created a bitmask. (01010101)
if ((value & bit_mask) == bit_mask)
then you know that every bit that was set in bit_mask is also set to value .
UPDATE: (after reading the question correctly)
You want to check if every second bit is set to 0. (Not set to 1, as my incorrect answer above shows)
There are two equally valid approaches: We make the bit mask the opposite (10101010)
Then use the OR operator:
if ((value | bit_mask) == bit_mask)
This checks that every bit that was zero in bit_mask is zero in value .
The second approach is to make the bit mask the same (01010101) and use the AND operator:
if ((value & bit_mask) == 0)
This checks that every bit that is one in bit_mask is zero in value .
source share