Java shifts left and right, java shifts left and right
I found a useful online compiler today and hope to share it with you.
In addition to java, there is also c ++..., the address is http://www.tutorialspoint.com/compile_java_online.php
In addition, I have reviewed the left and right shifts of java again today. Here is an example of negative numbers:
Positive and negative numbers are expressed in the form of complement in java.
For example,-2 indicates 11111111 11111111 11111111 in a computer.
1. Move left
-2 <2 that is,-2 shifted to the left. The result is: 11111111 11111111 11111111 11111000 (low position 0)
The above is the complement code. If the highest bit is 1, it indicates that this is a negative number. The complement code for a negative number is the original code of a positive number: "The highest bit is 1, the rest are reversed, and then 1 is added.
So let's look at it.-2 <2 actually indicates 10000000, 00000000, 00000000, 00001000 (-8)
2. Right Shift
If the high position is 1, then fill 1. If the high position is 0, then fill 0.
-2> 2: 11111111 11111111 11111111
10000000 00000000 00000000 00000001 (-1)
3. The shift operator can be used together with "="
A <= 2 indicates that the value after the Left shift of a is assigned to
4. Add: the java Virtual Machine shields large-end and small-end problems, and the internal is small-end.