Displacement operator in Java
Shift operators translate numbers on a binary basis. We know that in Java, both byte short and char types will be converted to int type first when calculating, and shift operation is no exception. The result of their shift will also become int type. Because the type of int is bit (), when shifting byte short char and int, it is stipulated that the maximum number of actual movements is bit. If it exceeds, it is calculated as n = n%, that is, the number of shifts and the number of shifts get the same result. When moving the value of long type (long is a bit), it is specified that the actual number of moves is the remainder of the sum of the number of shifts, that is, the number of shifts and the number of shifts get the same result. You can do the experiment yourself. Now we will introduce three displacement operators in Java. ) moves all the numbers to the left in binary form, and the corresponding numbers are moved out (discarded). The number of shifts required in the syntax format is, for example, the calculation process of shifting numbers to the left. First, convert them into binary numbers (if it is an int type, it is one byte long) Bytes, and then move out the two zeros of the high order (left) of the number, and all the other numbers move left. Finally, the two spaces in the lower order (right) are filled with zeros, and the final result is converted into decimal, which is a mathematical meaning. On the premise that the number does not overflow, the left shift of 1 bit is equivalent to the power of multiplication, and the left shift of n bits is equivalent to the power of multiplication. For example, the "= *" (signed right shift) operation rule shifts all numbers to the right in binary form, and shifts (discards) the high-order space complement sign bits, that is, the numbers that need to be shifted in the syntax format of positive complement and negative complement. For example, the binary form of the calculation process of shifting a number to the right is to shift the last two digits of the low order out. Because the number is positive, the final result obtained by padding zeros in the high order is that it is a mathematical meaning to convert it into decimal. Moving one bit to the right is equivalent to dividing the right by n bits. ) > >>& gt (Unsigned Right Shift) algorithm moves all digits to the right in binary form, and the corresponding digits are moved out (discarded) to fill the gap in the high position. Other structures and similar shift operations are usually used to optimize the speed of the code. It would be a good choice to replace multiplication and division. Let's give some examples to help you use the displacement operator. I/= ++ So I/ can be expressed as (I)+(I)+(I) Write the formula of (Q)+(Q) original code = q *+q * = q * *+) = q * lishixinzhi/article/program/.