why is 1>>32 == 1?

前端 未结 2 699
灰色年华
灰色年华 2020-11-27 18:40

I\'m wondering if perhaps this is a JVM bug?

java version \"1.6.0_0\" OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu13) OpenJDK 64-Bit Server VM (b

2条回答
  •  春和景丽
    2020-11-27 19:32

    It's not a bug. In n >> m, it only looks at the last five bits of m - so any number greater than 31 will be reduced to that number mod 32. So, (256 >> 37) == 8 is true.

    Edit: This is true if you're working with ints. If it's longs, then it looks at the last six bits of m, or mods by 64.

提交回复
热议问题