c# uint right bit-shift 意外结果

c# uint right bit-shift unexpected result

我很困惑为什么这会在 C# 中产生 0xffffffff,我原以为它会产生 0x0。表达式的类型是 uint.

Console.WriteLine(0xffffffff >> 32);

根据 documentation:

If the first operand is an int or uint (32-bit quantity), the shift count is given by the low-order five bits of the second operand (second operand & 0x1f).

第二个操作数是 32。32 & 0x1f 是 0。因此 >> 32 等价于 'shift this by 0 bits' 因此 'do nothing at all'。