public class TXs {
static void Leftbit () {
int i; Integer length 32 bits per/bit
int Num=0xffffffe; 1111 1111 1111 1111 1111 1111 1110//28
for (i=0;i<28;i++) {
The loop moves one bit to the left, discards the highest bit, and 0 is the lowest bit.
num=num<<1; 1111 1111 1111 1111 1111 1111 1110 0//29
1111 1111 1111 1111 1111 1111 1110 00//30
1111 1111 1111 1111 1111 1111 1110 000//31
1111 1111 1111 1111 1111 1111 1110 0000//-32
1111 1111 1111 1111 1111 1111 1100 0000//-64
SYSTEM.OUT.PRINTLN (num);
}
}
static void Rightbit () {
int i; Integer length 32 bits per/bit
int Num=0xffffffe; 1111 1111 1111 1111 1111 1111 1110//28
for (i=0;i<4;i++) {
The loop moves right one sign bit to the left, and the symbol bit
Num=num >> 1; 1111 1111 1111 1111 1111 1111 111//27
1111 1111 1111 1111 1111 1111 11//26
1111 1111 1111 1111 1111 1111 1//25
1111 1111 1111 1111 1111 1111//24
SYSTEM.OUT.PRINTLN (num);
}
}
Unsigned Right Shift
//
static void Unregist_rightbit () {
int i; Integer length 32 bits per/bit
int Num=0xffffffe; 1111 1111 1111 1111 1111 1111 1110//28
for (i=0;i<4;i++) {
The loop moves one at a time to the right one ignores the sign bit extension. 0 complement Maximum bit
Num=num >>> 28; 1111 1111 1111 1111 1111 1111 111//27
1111 1111 1111 1111 1111 1111 11//26
1111 1111 1111 1111 1111 1111 1//25
1111 1111 1111 1111 1111 1111//24
SYSTEM.OUT.PRINTLN (num);
}
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
Leftbit ();
Rightbit ();
System.out.println ("================");
Unregist_rightbit ();
}
}
Java shift Operator Experiment Program:<< (left), >> (with symbol right shift) and >>> (unsigned Right shift)