如何在c中执行有符号右移?
像-25 >> 3。
我尝试这样:
10011001 >> 3 == 00010011
但结果是-4。
根据标准6.5.7p5
The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 /2E2. If E1 has a signed type and a negative value, the resulting value is implementation-defined.
结果是实现定义的,您应该查找它是如何定义的。
假设二进制补码和有符号右移,-25
is 11100111
,将其移动 3 将导致11111100
这是-4
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)