java
左侧位移 :<< 表示这个数乘以2的n次方右侧位移:>> 表示除以这个数的n次方
示例:y<<1 等价于 y*(Math.pow(2, 1))y<<2 等价于 y*(Math.pow(2, 2))y<<3 等价于 y*(Math.pow(2, 3)) y<<4 等价于 y*(Math.pow(2, 4))y<<5 等价于 y*(Math.pow(2, 5))y>>1 等价于 y/(Math.pow(2, 1))y>>2 等价于 y/(Math.pow(2, 2))y>>3 等价于 y/(Math.pow(2, 3)) y>>4 等价于 y/(Math.pow(2, 4))y>>5 等价于 y/(Math.pow(2, 5))
// java 代码 运算结果有些出入哦。。。。int y=10;System.out.println(( y<<1 )+' << '+(y*(Math.pow(2, 1))));System.out.println(( y<<2 )+' << '+(y*(Math.pow(2, 2))));System.out.println(( y<<3 )+' << '+(y*(Math.pow(2, 3))));System.out.println(( y<<4 )+' << '+(y*(Math.pow(2, 4))));System.out.println(( y<<5 )+' << '+(y*(Math.pow(2, 5))));System.out.println('------ 分割线 ------'); y=1000;// (如下 >> 示例 : y 的值不能写太小 ,否则强制类型转换了) System.out.println(( y>>1 )+' >> '+(y/(Math.pow(2, 1))));System.out.println(( y>>2 )+' >> '+(y/(Math.pow(2, 2))));System.out.println(( y>>3 )+' >> '+(y/(Math.pow(2, 3))));System.out.println(( y>>4 )+' >> '+(y/(Math.pow(2, 4))));System.out.println(( y>>5 )+' >> '+(y/(Math.pow(2, 5))));
运行结果为:20 << 20.040 << 40.080 << 80.0160 << 160.0320 << 320.0------ 分割线 ------500 >> 500.0250 >> 250.0125 >> 125.062 >> 62.531 >> 31.25
取次方结果还可以,但是>> 运算有些出入。。