First, there are three kinds of shift operators whose operation type supports only: Byte/short/char/int and long five.
<< left operator, which means that the binary data of the left-hand operand is moved to the left * bit, the empty vacancy is filled with 0, and the redundant bits are discarded . (Equal to the N-second party multiplied by 2)
>> Right shift operator, binary data to the right to move the * bit, after the second data to wipe out a few? (This is a good set, but it's a personal understanding)(equivalent to the N-second side of 2)
>>> the unsigned right-shift operator, regardless of whether the top bit is 0 or 1 before the move, the empty portion produced on the left side of the right shift is filled with 0来.
Here we'll take a demo to help understand:
public static void Main (string[] args) {
int a =;
int B = A << 2;//left 2, equivalent to 2 times of 16 * 2, that is, 4
int c = A >> 2;//right Shift 2, which is equivalent to 16/2 of 2 times, that is, 16/4
SYSTEM.OUT.P Rintln ("A's binary data is:" + integer.tobinarystring (a));
System.out.println ("a left-shifted binary data is:" + integer.tobinarystring (b));
System.out.println ("A right-shifted binary data is:" + integer.tobinarystring (c));
System.out.println ("A left-shift value is:" + b);
System.out.println ("A right-shifted value is:" + C);
}
View the results of the run, as shown in the figure:
First, the binary data of 16 is: 10000;
Two left, 10000 into 10000;
Move right two digits, 10000 to 100;
After converting the resulting binary data into normal data,
A left-shift value is 64, 16 * 2 of the 2-second party (16 * 4).
The value of a right shift is 4, which is 16/2 of the 2-second square (16/4).
Is it much simpler to read the demo and understand the shift operator?
Above this Java on the shift operator demo and summary (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.