Reprint please indicate the source: http://blog.csdn.net/droyon/article/details/9336083
">>>" Unsigned Right shift
Action rule: Regardless of positive negative number, the front is 0.
">>" Move right
Action rule: Positive number front 0, negative number ahead of 1
"<<" Move left
Action rule: Regardless of positive negative, after 0.
public class Bitmovetest {public static void main (String args[]) {//>> right forward complement sign bit//>> equivalent to 2, left-shifted equivalent to multiply by 2 in
T i=11;
int j=-13;
System.out.println ("Move right, front bit complement symbol bit"); Machine value: 0000 0000 0000 0000 0000 0000 0000 1011//complement value: 0000 0000 0000 0000 0000 0000 0000 1011//Right shift one: 000 0 0000 0000 0000 0000 0000 0000 0101 ("System.out.println value is:" + (11>>1)); The result is: 5//Machine value: 1000 00 00 0000 0000 0000 0000 0000 1101//Complement value: 1111 1111 1111 1111 1111 1111 1111 0011//Right Shift one: 1111 1111 1111 1111 1111 1111 1111 1001 (complement)//Result code: 1000 0000 0000 0000 0000 0000 0000 0111 ( -7) System.out.println (" -13>&
Gt;1 value is: "+ (j>>1));//The result is: -7 System.out.println (" *************************************\n ");
System.out.println ("Move left, back bit 0"); Machine value: 0000 0000 0000 0000 0000 0000 0000 1011//complement value: 0000 0000 0000 0000 0000 0000 0000 1011//left one: 000 0 0000 0000 0000 0000 0000 0001 0110 System.out.println ("11&The lt;<1 value is: "+ (i<<1)); The result is: 22//Machine value: 1000 0000 0000 0000 0000 0000 0000 1101//Complement value: 1111 1111 1111 1 111 1111 1111 1111 0011//left one: 1111 1111 1111 1111 1111 1111 1110 (complement)//Results Original code: 0110 1000 0000 0000 0000 0000 0001 1010 ( -26) System.out.println (" -13<<1 value is:" + (j<<1)); The result is: -26 System.out.println ("*********
\ n ");
>>> unsigned Right Shift 0 System.out.println ("Unsigned right shift, front complement 0"); Machine value: 0000 0000 0000 0000 0000 0000 0000 1011//complement value: 0000 0000 0000 0000 0000 0000 0000 1011//Right shift one: 000 0 0000 0000 0000 0000 0000 0000 0101 ("System.out.println value is:" + (11>>>1)); The result is: 5//Machine value : 1000 0000 0000 0000 0000 0000 0000 1101//Complement value: 1111 1111 1111 1111 1111 1111 1111 0011//Right Shift one: 0111 1111 1111 1111 1111 1111 1111 1001 (complement is also the original code) SYSTEM.OUT.PRINTLN (" -13>>>1 value is:" + (j>>>1)); The result is: 21474836 System.out.println ("**********************\ n ");
}
}
Operation Result:
To the right, the previous bit complement sign bit
11>>1 value is: 5
-13>>1 value is: -7
************************************* to
move left, The value of the next bit complement 0 11<<1 is: The value of -13<<1 is
: -26 ************************************* The unsigned
right SHIFT, The value of the front complement 0 11>>>1 is: 5
-13>>>1 value is: 2147483641
******************************** *****