The shift operator is the translation of a number on the basis of a binary. the rules for panning direction and filling numbers are divided into three:<< (left), >> (with symbol right), and >>> (unsigned Right shift).
The calculation rules are as follows:
the ① left n is equal to the n-th side multiplied by 2.
② The right shift n is equal to the n-th squared by 2. Here is to take the Shangha, the remainder will not be.
③>>> (unsigned Right shift)
Operation rules:
Press Binary The form moves all numbers to the right by the corresponding number of digits, the low position is shifted out (discarded), and the upper seat is 0. For positive numbers, it is the same as a signed right shift, which is different for negative numbers. Other structures and >> similar.
Example
[Java] view plaincopyprint?
- long &NBSP;A&NBSP;=&NBSP; 0x3 ;&NBSP;&NBSP;
- long &NBSP;B&NBSP;=&NBSP; 30 ;&NBSP;&NBSP;
- long longleft = a << b;
- system.out.println (longLeft);
- system.out.println (0x3 &NBSP;<<&NBSP; 30
- system.out.println ("-----"
- system.out.println (Math.pow (-2 ,&NBSP; 31
- system.out.println (Integer.MIN_ VALUE);
- system.out.println ("-----"
- system.out.println (Math.pow (2 ,&NBSP; 31 1
- System.out.println (Integer.max_value);
Results
[plain] view plaincopyprint?
- 3221225472&NBSP;&NBSP;
- -1073741824
- -----
- -2.147483648E9
- -2147483648
- -----
- 2.147483647E9
- 2147483647
Displacement operations in Java