javaThe shift operator in：<<,>>,>>> conclude_Intefrankly

javaThe shift operator in：<<,>>,>>> conclude

There are three shift operators in java

<< : Left shift operator，num << 1, equivalent tonum multiply by2

>> : Right shift operator，num >> 1, equivalent tonum divided by2

>>> : Unsigned right shift, ignoring sign bits, empty bits are filled with zeros

Here's a look at how each of these shift operations is used

``` 1 /**
2  *
3  */
4 package com.b510.test;
5
6 /**
7  * @author Jone Hongten
8  * @create date：2013-11-2
9  * @version 1.0
10  */
11 public class Test {
12
13     public static void main(String[] args) {
14         int number = 10;
15 // Raw number binary
16         printInfo(number);
17         number = number << 1;
18 //Shift one place left
19         printInfo(number);
20         number = number >> 1;
21 //Shift one place to the right
22         printInfo(number);
23     }
24
25     /**
26 * Output a binary number of int
27      * @param num
28      */
29     private static void printInfo(int num){
30         System.out.println(Integer.toBinaryString(num));
31     }
32 }```

The results of the run are.

```1010
10100
1010```

Let's align the results above.

``` 43210 bits
--------
1010 Decimal: 10 Original number
10100       decimal system：20      Shift one place to the left       number = number << 1;
1010       decimal system：10      Shift right one place       number = number >> 1;```

After seeing the above demo, do you now understand a lot about left and right shifts?

as far as sth is concerned：>>>

Unsigned right shift, ignoring sign bits, empty bits are filled with zeros

value>>>num -- num Specify the value to be shiftedvalue Number of bits moved。

The rules for unsigned right shifts remember only one thing： Ignoring symbolic bit extensions，0 complementary maximum Unsigned right shift operator>>> Just for32 bits and64 The value of the bit has meaning

E | hongtenzone@foxmail.com B |http://www.cnblogs.com/hongten

Recommended>>
1、Java Concurrency Practice ManualConcepts of Concurrency
2、Frontend cutCall Baidu map API
3、Android talks about wrapping those things BaseActivity and BaseFragment II
4、Intermediate Service creation maintenance and horizontal scaling in dockerswarm 45
5、SelectingmultiplecheckboxesinsideaGridViewcontrol

已推荐到看一看 和朋友分享想法
最多200字，当前共 发送

已发送

确定
分享你的想法...
取消

确定
最多200字，当前共

发送中