当前位置:编程学习 > JAVA >>

这段描述是什么意思?



这段描述出自《java编程思想第4版》,谁能解释下这个2的5次方和 int是32位是怎么关联上的?

我觉得毫无关系。。 --------------------编程问答-------------------- 你理解错了
x << y
y <= 32 才有意义,因为int是32位的
右端5位指的是 y 的二进制的右五位 --------------------编程问答-------------------- 1楼,你说的我知道。

如果想不超过一个int的范围,我认为位移可以是 1 <= x < 32 , 为什么这里说 要 <= 5. --------------------编程问答--------------------
引用 2 楼 junnyfeng 的回复:
1楼,你说的我知道。

如果想不超过一个int的范围,我认为位移可以是 1 <= x < 32 , 为什么这里说 要 <= 5.


因为   0000 0000 0000 0000 0000 0000 0001 1111   就是32,数数几个1 --------------------编程问答-------------------- If you shift a char, byte, or short, it will be promoted to int before the shift takes place, and the result will be an int. Only the five low-order bits of the right-hand side will be used. This prevents you from shifting more than the number of bits in an int.

right-hand side指的应该是1>>8的8那个部分

像这样的描述就明白了:低5位二进制是指移位操作符的右操作数,而不是被操作数本身。

这作者写得晦涩,直接说不能超过32不就得了。翻译没表达清楚,右边的低5位,操作数的低5位也在右边的,这就让人产生误会。
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,