Bitwise operators behave well only with degrees 2:
0010 | 0100 ------ 0110 // both bits are set 0110 & 0100 ------ 0100 // nonzero, ie true: the flag is set
If you try to do the same with arbitrary numbers, you will get unexpected results:
0101 // 5 | 1100 // 12 ------ 1101 // 13
Which contains possible (arbitrary) numbers in the form of set flags: 0001 (1), 0100 (4), 0101 (5), 1000 (8), 1001 (9), 1100 (12), 1101 (13)
So instead of giving two options, you just gave six.
György andrasek
source share