Rectangle 27 1

C++ Logical AND Operator?


flags |= (1 << i);

The bitwise OR in |= will "add" bits to your bitset flags, whereas the bitwise AND can only remove bits.

You have mixed up | and &. Your expected result corresponds to the iteration of:

Note
Rectangle 27 1

C++ Logical AND Operator?


flags |= (1 << i);

The bitwise OR in |= will "add" bits to your bitset flags, whereas the bitwise AND can only remove bits.

You have mixed up | and &. Your expected result corresponds to the iteration of:

Note