The shift operator is to translate a number based on binary. There are three types of rules based on the direction of translation and the number filling rule: <(left shift),> (shifted right with a symbol) and> (shifted right without a symbol ).
During the shift operation, the result after the byte, short, and char types are shifted to the int type. When the byte, short, Char, and INT types are shifted, the actual number of moves is the number of moves and the remainder of 32, that is, the result of 33 shifts is the same as that of 1 shift. When moving a long value, the actual number of moves is the number of moves and the remainder of 64, that is, the result of moving 66 times is the same as that of moving 2 times.
After 386, the hardware will shift the shift to perform the modulo operation on the font length. The 32-bit shift to the right will shift the 0-bit shift to the right (the CPU moves the 32-bit shift to the right to perform the modulo operation on the 32-bit font length to get 0 ), therefore, the 32-bit right shift of 9 is still 9. You can change the for loop conditions, for example, to I <= 64, you will find that the results are the same.
The following table describes the movement rules and usage of the three shift operators:
<Operation rule:In binary format, all numbers are moved to the right to the corresponding number of digits. The high position is removed (discarded), and the low position is filled with zero.
Syntax format:
Number to be shifted <number of shifts
For example, if the value is 3 <2, the value 3 is shifted to two places.
Computing process:
3 <2
First, convert 3 to a binary number 0000 0000 0000 0000 0000 0000 0000 0011. Then, remove the two zeros in the upper (left) Position of the number. All the other digits are shifted to the left, at last, the two vacancies in the low position (on the right) are filled with zeros. The final result is 0000 0000 0000 0000 0000 0000 0000 1100, And the decimal value is 12. mathematical significance:
If the number does not overflow, for positive and negative numbers, moving one to the left is equivalent to multiplying the power of 1 by 2, and moving n to the left is equivalent to multiplying the power of N2.
> Operation rules:In binary format, all numbers are moved to the right to correspond to the numbers of the steep digits. The low position is removed (discarded). The high position is filled with the sign bit, that is, the positive number is supplemented with zero, and the negative number is supplemented with 1.
Syntax format:
Number to be shifted> Number of shifts
For example, if the value is 11> 2, the number 11 is shifted to two places.
Computing process:The binary format of 11 is: 0000 0000 0000 0000 0000 0000 0000. Then, remove the last two digits of the low position. Because the number is positive, it is set to zero at the high position. The final result is 0000 0000 0000 0000 0000 0000 0000 0010. Converting to decimal is 3. mathematical meaning: Shifts one digit to the right is equivalent to dividing 2, and shifts n digits to the right is equivalent to dividing by the Npower of 2.
>>> Operation rule:In binary format, all the numbers are moved to the right, corresponding to the steep digits, the low position is removed (discarded), and the high position is filled with zero. For a positive value, it is the same as the shifted right value. For a negative number, it is different.
Other structures are similar to>.