Shift operators translate numbers on a binary basis. According to the direction of translation and the rules of filling in numbers, there are three kinds:> (signed right shift) and >; & gt& gt (unsigned right shift).
The movement rules and usage of the three shift operators are as follows:
& lt& lt operation rule: shift all numbers to the left by the corresponding digits in binary form, shift them out (discard) at high places, and fill in the blanks at low places.
Syntax format:
The number to shift
For example: 3
Calculation process:
3 & lt& lt2
First, 3 is converted into a binary number 00000000000000000011,then two zeros in the upper (left) bit of this number are shifted out, and the other bits are shifted two places to the left. Finally, two spaces in the lower (right) bit are filled with zeros. Then the final result is 000000000000000000000000000001100, and the decimal conversion is 12. Mathematical significance:
On the premise that the number does not overflow, whether it is positive or negative, moving one place to the left is equivalent to multiplying 2 by 1 power, and moving n places to the left is equivalent to multiplying 2 by n power.
& gt& gt operation rule: shift all the numbers corresponding to the high bits to the right in binary form, and move out (discard) the high-bit space complement sign bits, that is, positive numbers complement zero and negative numbers complement 1.
Syntax format:
Number to shift >; & gt number of shifts
Such as11>; & gt2, the number 1 1 is shifted 2 places to the right.
Calculation process: The binary form of 1 1 is: 0000000000000101,and then the last two bits are shifted out. Because the digits are positive, zeros are filled in the high bits. The final result is 00000000000000000000000000000000000010. Decimal conversion to 3.
Mathematical meaning: moving 1 bit to the right is equivalent to dividing by 2, and moving n bits to the right is equivalent to dividing by the n power of 2.
& gt& gt& gt operation rule: shift all numbers to the right in binary form to the corresponding high-order digits, shift them out (discard) at low levels, and fill in the blanks at high levels. For positive numbers, the signed right shift is the same, but for negative numbers, it is different.
Other structures and >; & gt similar.