Binary operator

Binary operators:

1. Invert operation ~

             ~a

For the binary of a, change 1 to 0 and 0 to 1


2. Left shift operator <<

            a<<2

Shift the binary of a to the left by two bits, the vacant bits on the right are filled with 0, and the left overflow bits are discarded directly


3. Right shift operator >>

            a>>2

Shift the binary of a to the right by two bits, the vacant bits on the left are filled with 0, and the bits removed on the right are discarded


4. Bitwise XOR operator ^

             a^b

For the binary of a and b, if the same bit is the same, it is 0, and if it is different, it is 1


5. Bitwise AND operator &

              a&b

For the binary of a and b, if the same bit is 1, it is 1, otherwise it is 0


6. Bitwise OR operator |

              a|b

For the binary of a and b, if one of the same bits is 1, it is 1, otherwise it is 0

Published 190 original articles · 19 praises · 200,000+ views

Guess you like

Origin blog.csdn.net/zengchenacmer/article/details/29622147