位移运算符

package gather;

public class TestTwo {

    public static void main(String[] args) {

        /**
         *   >>> 忽略符号位,空位用0补齐
         */
        
//        int x = 7;
        int x = -7;
        binary(x);
        
        x =  x >>1; 
        binary(x);
        
        x = x << 2;
        binary(x);
        
        x = x >>> 2;
        binary(x);
        
        
        /**
         * 
         * -7时执行结果
         * 
----------------
-7
11111111111111111111111111111001
----------------
-4
11111111111111111111111111111100
----------------
-16
11111111111111111111111111110000
----------------
1073741820
111111111111111111111111111100(空位0补)
         * 
         */
        
        
    }
    
    private static void binary(int num){
        System.out.println("----------------"); 
        System.out.println(num); 
        System.out.println(Integer.toBinaryString(num));
    }
    
}

 

posted @ 2018-01-25 13:49  aLa神灯  阅读(118)  评论(0编辑  收藏  举报