SickWorm的博客

Java右移每32位(64位)循环

Java  ·  

        long a = 33;
        for (int i = 0; i < 64; i++) {
            System.out.println(i + " " + (a >> i));
        }

结果:

0 33
1 16
2 8
3 4
4 2
5 1
6 0
7 0
...
62 0
63 0

而如果是int, short, byte:

        int a = 33; // short, byte 也一样
        for (int i = 0; i < 64; i++) { // i 为 short, byte也一样
            System.out.println(i + " " + (a >> i));
        }

结果是:

0 33
1 16
2 8
3 4
4 2
5 1
6 0
7 0
...
30 0
31 0
32 33
33 16
34 8
35 4
36 2
37 1
38 0
39 0
40 0
41 0
...
62 0
63 0

版权所有,转载请注明出处:
https://sickworm.com/?p=486