java中左移<<
public static strictfp void main(String[] args) {
int num=5;
System.out.println(Integer.toBinaryString(num));
num <<= 1;
System.out.println(Integer.toBinaryString(num));
//System.out.println(num&1);
num <<= 1;
System.out.println(Integer.toBinaryString(num));
num <<= 1;
System.out.println(Integer.toBinaryString(num));
num <<= 1;
System.out.println(Integer.toBinaryString(num));
}
101
1010
10100
101000
1010000
java中右移>>>
public static strictfp void main(String[] args) {
int num=5;
System.out.println(Integer.toBinaryString(num));
num >>>= 1;
System.out.println(Integer.toBinaryString(num));
num >>>= 1;
System.out.println(Integer.toBinaryString(num));
num >>>= 1;
System.out.println(Integer.toBinaryString(num));
}
101
10
1
0