打赏

java中的左右移

 1 package scanner;
 2 
 3 public class LeftMove {
 4     
 5     public static void main(String[] args) {
 6         
 7         int i = 1;
 8         
 9         System.out.println("i 右移两位:" + (i>>2) ); //0
10         
11         System.out.println("i 左移两位:" + (i<<2) ); //4
12         
13         for (int j = 0; j < 4; ++j) {
14             
15             
16             int  result  = 1 << ((j + 2) % 4);
17             
18             //  "<<"为左结合性
19             
20             System.out.println("1 << ((" + j + " + 2) % 4)) = " + result);
21             
22         }
23                 
24     }
25 }

 

posted @ 2016-03-26 22:21  海米傻傻  阅读(428)  评论(0编辑  收藏  举报