I have a 32 bit int I can only access it 8 bits at a time. I need to find out if every even bit is set to 0 and return 0 if its true and 1 otherwise.
So far I am goi
EDIT: I got confused by the original question and followed OP in the negation thing - so basically this solves the reverse problem. Andrew Sheperd's edited solution starts back from the original problem and solves it in 1 step. Rudy Velthuis also offers an interesting approach.
If your bytevalue AND 01010101 == 01010101 all bits selected by the mask are 1 in the original byte value.
In sortof pseudo C:
unsigned char mask = 0x55;
if ((byteval & mask) == mask) {
printf ("all set");
}
or a slightly fancier xor based variation
unsigned char mask = 0x55;
if (!((byteval & mask) ^ mask)) {
printf ("all set");
}
Btw, the if is very easy to get rid of for the final result ...