Q:

Logical & bitwise AND

I am using bitwise operators to store some boolean values in a variable. I assume i'm storing them appropiately, although here are my assignments:
int bit = 0;
bit |= 1;
bit |= 2;
bit |= 4;
bit |= 8;

What i am unsure of is the checking part. I have a simple knowledge about the difference between logical and bitwise operators. Here's how i check the values:
if ((bit & 1) && (bit & 2) && (bit & 8)) {
    std::cout << "a" << std::endl;
} 
else {
    std::cout << "b" << std::endl;  
}

I want to know if that kind of conditional is correct (i've done some tests, but i might be missing something) and also i want to know if i can check multiple bits at the same time, for example:
if (bit && (1 & 2 & 8) {
    std::cout << "a" << std::endl;
} 
else {
    std::cout << "b" << std::endl;  
}

I know that the last won't work as desired (at least that's what tests gave me), but i wanted to illustrate my idea.

A:

i want to know if i can check multiple bits at the same time

Yes, you can do that but your code is not correct.

1 & 2 & 8 will always be zero. You need to use 1 | 2 | 8.
bit && (1 & 2 & 8) is not correct because of the above.

You can use:
if ( (bit & (1 | 2 | 8)) == (1 | 2 | 8) ) {
    std::cout << "a" << std::endl;
} 
else {
    std::cout << "b" << std::endl;  
}

The expression (bit & 1) && (bit & 2) && (bit & 8) is logically the same as the expression (bit & (1 | 2 | 8)) == (1 | 2 | 8)
See it working at https://ideone.com/KdGjiO.

