444444444>>>-5=3搞不懂原理

444444444>>>-5=3

3个回答

[quote]
If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x1f (0b11111). The shift distance actually used is therefore always in the range 0 to 31, inclusive.

If the promoted type of the left-hand operand is long, then only the six lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (§15.22.1) with the mask value 0x3f (0b111111). The shift distance actually used is therefore always in the range 0 to 63, inclusive.
[/quote]

iteye_12441 对了,3ks
7 年多之前 回复
iteye_171 这里是移动27位啊，，哪里移动30位了？ 11010011111011010111100011100也才29位啊。。。移动了27位，剩下11，不就是=3么？
7 年多之前 回复
iteye_12441 按照你所说的理论,有些情况是符合的,有些情况则不对. -----------------------------------------这是分割线-------------------------------------------- 符合的例子 444444444>>>-31=222222222 也就是 11010011111011010111100011100>>>11111111111111111111111111100001=1101001111101101011110001110 取后面5位,也就是 11010011111011010111100011100>>>00001(10进制1)=1101001111101101011110001110 移动1位,结果正确 -----------------------------------------这是分割线-------------------------------------------- 不符合的例子: 444444444>>>-5=3 也就是 11010011111011010111100011100>>>11111111111111111111111111111011=11 按照你所说,取后面5位,也就是 11010011111011010111100011100>>>11011(10进制27)=11 这里就不对了,这里实际上是移动了30位,而不是27位 希望大大再补充资料,把这个问题,帮我弄清楚
7 年多之前 回复

1、-5在计算机中保存的时候是补码方式即

2、java中的<<， >>, >>>移位是周期以为

3、根据上面公式444444444 >>> (二进制1111 1111 1111 1111 1111 1111 1111 1101 mod 32)

1、-5在计算机中保存的时候是补码方式即

2、java中的<<， >>, >>>移位是周期移位

3、根据上面公式444444444 >>> (二进制1111 1111 1111 1111 1111 1111 1111 1101 mod 32)

iteye_171 补充一点，mod多少，根据y情况。如果是long那就是64了，而不是32
7 年多之前 回复