Bitwise AND and bitwise OR

Bitwise AND , the operator "&", binary operators, which feature allows binary phase two numbers and only case of two bits are 1, the result is 1, the remaining cases to zero. Such as:

1&1=1
1&0=0
0&1=0
0&0=0

 

Bitwise or , the operator "|", binary operators, which feature allows two or binary phase, only two bits are 0 love prizes, the result is 0, 1 for the remaining cases. Such as:

1|1=1
1|0=1
0|1=1
0|0=0

 

Negated , the operator "~", unary operators, higher priority than the binary operator, which allows a number of function bitwise binary bits, i.e., 1 to 0, 0 to 1.

 

Using these three bit operation, to achieve the switch flag. Composite features and enumeration. 1 with certain features, such as, 2, 4, 8, 16 ... etc, represents A, B, C, D, E ... 

Then the following scenarios:

1. As described in Zhang ABC has three states: ZS = A | B | C 

2. BDE John Doe has three states: LS = B | D | E

3. Check whether the seating state comprises D: ZS & D == D

4. John Doe cancel E state: LS = LS & ~ E

 

Guess you like

Origin www.cnblogs.com/howtrace/p/11491136.html