The displacement operators in Java are the places where the beginners confused, especially the mathematics foundation. At least I was this. Shift Operators is used to operate, only on the basic integer type. They are divided into: left shift operation symbol (<<); right shift operation symbol (>>); Java has a special, no fixed-to-right shift operator (>>>) (1) left mobile operation Rat: Move the number of operations to the left, the number of mobile bits is specified by the right operand, after the left shift, the low position will be automatically completed (0). (2) Right Move operator: In turn, move the operands to right, the number of movements is also specified by the right operand. Note: Face with the number of positive negative numbers, the symbol extension will be used. If the original value is positive, the high position is added to 0; if the original value is negative, the high level is 1. (3) There is no right-shifted operation operator (>>>): use 0 supplements, meaning, whether it is a positive or negative, it is 20. If your operand is like CHAR, BYTE, SHORT, it is transformed into int, just as mentioned earlier, the displacement operator can only be used on the type INT. Example: Public class urshift {public static void main (string [] args) {INT i = -1; I >>> = 10; system.out.println (i);}} java: 4194303 How to work: use binary representation When the highest bit is 0 or 1 to indicate that the positive and negative 0 indicates that positive 1 indicates negative (not only up to 1 but all high positions)
>> The left subsidy bit is shifted by the sign right shift right and right shifts >>> is no symbol right shift right shift to the left
So both are the same on the left side of the same number, but there is a difference between the negative number >> Buy 1 >>>
So -111111 1111 1111 1111 1111 1111 1111 1111Bi >>> = 10 after 0000 00 0011 1111 1111 1111 1111 1111B = 4194303