java 位移运算 >>

 时间:2024-12-25 19:13:49

1、左侧位移 :<< 表示这个数乘以2的n次方右侧位移:>> 表示除以这个数的n次方

2、示例: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))

3、// 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))));

4、运行结果为:20 << 20.040 << 40.080 << 80.0160 << 160.0320 << 320.0------ 分割线 ------500 >> 500.0250 >> 250.0125 >> 125.062 >> 62.531 >> 31.25

  • 古代战争竞技场攻略
  • 暗黑3传奇宝石属性及升级概率
  • 暗黑3圣教军攻略
  • 暗黑3一波精英怪三份掉落全职业实战方法
  • 暗黑三17赛季法师攻略
  • 热门搜索
    电脑怎么装双系统 虾仁炒什么好吃 减肥的最快方法 成都有什么好吃的 打屁屁的方法 凉拌土豆丝的家常做法 分析方法有哪些 西米的做法大全 维c银翘片怎么样 最适合懒人的减肥方法