|
&and, two are 1 is 1, the others are 0
| Or, two 0 is 0, the other is 1
^ Or, two identical are 0, two different are 1
&= a&= b; is equal to a = a&b;
|= as above
^= as above
skill:
And, it can be used to mask out some bits, or to reserve some bits, with a number, the zero bit can be used to mask, and 1 bit can be used to keep the original state
0xffff&0x00ff == 0x00ff, mask the high bit 0xff00, reserve the low bit 0x00ff;
Or, it can be used to set some bits, because the original 1 bit will not be changed, only the zero bit can be changed, and multiple settings can be combined.
0x000f | 0x00f0 == 0x00ff;
Then you can use and to determine whether this bit is set
0x00ff&ox00f0 == 0x00f0; |
|