【发布时间】:2021-11-05 13:36:22
【问题描述】:
我收到一段用java编写的代码,使用>>>操作,快速搜索后发现它是"shifts a zero into the leftmost position",但我找不到相等的操作in python。
以下代码在python中的类似操作是什么?
((CRC & 0xFF00) >>> 8)
【问题讨论】:
-
我很确定 python 的
>>与 Java 的>>>相同,并且它没有带符号的移位(移位时复制最高有效位,而不是使用 0) -
在 Python 中,
CRC & 0xFF00等同于CRC & 0x0FF00。 IIRC,如果您想要符号扩展,您可以使用CRC & 0x1FF00从以下>>获得适当的符号扩展结果。 -
bitwise operations on integers types的python文档