Python shift operator and python Operator
1. Binary
>>> bin( 1 )'0b1'>>> bin( 10 )'0b1010'>>> a = 0b10>>> a2>>>
2. Shift Operator (>><): The Arrow shifts to the left. The Arrow shifts to the right.
For example, in decimal 1 ---> the binary value is 0000 0001.
1 <1: Move 1 to the left
0000 0001 ---> 0000 0010 (2)
1 <2: Move two places to the left
0000 0001 ---> 0000 0100 (4)
2 <2: 2: Move two places to the left
0000 0010 ---> 0000 1000 (8)
>>> 1 << 12>>> 1 << 24>>> 2 << 28>>>
Moving to the right is the same principle. First, convert the number to binary, and then move the corresponding number of digits to the right.
>>> 1 >> 10>>> 2 >> 11>>> 3 >> 11>>> 6 >> 13>>>
6 (0000 0110) ----> after (6> 1) 0000 0011 (3)
1. Operation: when the values of A and B are both 1, the calculation result of A and B is 1. Otherwise, it is 0 (OPERATOR :&)
2. Or operation: when the value of A or B is 1, the calculation result of A, B or is 1; otherwise, it is 0 (OPERATOR: |)
3. Exclusive or operation: When A is 1 different from B, the calculation result of A and B is 1. Otherwise, it is 0 (OPERATOR: ^)
4. Flip by bit (reverse by bit): returns the binary number of numbers in the memory in decimal order 0 to and takes 0 (OPERATOR :~)
>>> 1 & 11>>> 1 & 00>>> 4 & 10>>>
>>> 1 | 11>>> 1 | 01>>> 4 | 15>>>
>>> 1 ^ 10>>> 7 ^ 815>>>
>>> ~5-6>>> ~20-21>>>