当前位置:网站首页>Operator < <> > fool test case

Operator < <> > fool test case

2022-07-04 06:19:00 A master of East and West

Always remember : On the left is the operand , On the right yes Move digits ( This is the same for shift left and shift right )

public class Test {
    
    //  Start from the limit , Fool test 
    public static void main(String[] args) {
    
        /***  Move left test  ***/
        //  Operands   Shift left arrow   Shift left digit   Binary system   Decimal system 
        System.out.println(1 << 0); // 1  Moving to the left 0 position , 1 = 1
        System.out.println(1 << 1); // 1  Moving to the left 1 position , 10 = 2
        System.out.println(1 << 2); // 1  Moving to the left 2 position , 100 = 4
        System.out.println(1 << 3); // 1  Moving to the left 3 position , 1000 = 8
        System.out.println(1 << 4); // 1  Moving to the left 4 position ,10000 = 16

        System.out.println(2 << 1); // 2  Moving to the left 1 position ,10  change  100  namely  4
        System.out.println(2 << 2); // 2  Moving to the left 2 position ,10  change  1000  namely  8
        System.out.println(2 << 3); // 2  Moving to the left 3 position ,10  change  10000  namely  16
        System.out.println(2 << 4); // 2  Moving to the left 4 position ,10  change  100000  namely  32

        System.out.println(3 << 1); // 3  Moving to the left 1 position ,11  change  110  namely  6
        System.out.println(3 << 2); // 3  Moving to the left 2 position ,11  change  1100  namely  12
        System.out.println(3 << 3); // 3  Moving to the left 3 position ,11  change  11000  namely  24
        System.out.println(3 << 4); // 3  Moving to the left 4 position ,11  change  110000  namely  48

        /***  Move right test  ***/
        //  Operands   Shift right arrow   Shift the number of digits to the right   Binary system   Decimal system 
        System.out.println(1 >> 0); // 1  Move right 0 position , 1 = 1
        System.out.println(1 >> 1); // 1  Move right 1 position , 0 = 0
        System.out.println(1 >> 2); // 1  Move right 2 position , 0 = 0
        System.out.println(1 >> 3); // 1  Move right 3 position , 0 = 0
        System.out.println(1 >> 4); // 1  Move right 4 position , 0 = 0

        System.out.println(2 >> 0); // 2  Move right 1 position ,10  change  10  namely  2
        System.out.println(2 >> 1); // 2  Move right 1 position ,10  change  01  namely  1
        System.out.println(2 >> 2); // 2  Move right 2 position ,10  change  00  namely  0
        System.out.println(2 >> 3); // 2  Move right 3 position ,10  change  00  namely  0
        System.out.println(2 >> 4); // 2  Move right 4 position ,10  change  00  namely  0

        System.out.println(3 >> 1); // 3  Move right 1 position ,11  change  01  namely  1
        System.out.println(3 >> 2); // 3  Move right 2 position ,11  change  00  namely  0
        System.out.println(3 >> 3); // 3  Move right 3 position ,11  change  00  namely  0
        System.out.println(3 >> 4); // 3  Move right 4 position ,11  change  00  namely  0
    }

}

原网站

版权声明
本文为[A master of East and West]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207040617140734.html