为什么 3 >> 32 等于 3?

Why is 3 >> 32 equal to 3?

why 3 right shift 32 is equal to 3 and not 0.

我在 nodeJs 和 Java

中得到了这些结果

这是 Java 语言规范的一部分。右手操作数被换行,因此它始终在 0 - bits 范围内,其中 bits 是左手操作数的位数.由于您要移动 32 位整数,因此右手操作数包含在 0 到 31 之间。32 变为 0,33 变为 1 等

查看 Java language specification for shift operators:

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.