Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在用 Python 制作一个 TF2 背包查看器,并且我有一个 32 无符号长的库存令牌。前 16 位对我来说并不重要。C中的常用方法类似于
(a<<16)>>16
获取最后 16 位。但是Python不是C,上面的操作是行不通的。如何指定 Python 应该对这个变量使用 int32?
您可以使用按位与运算符 ( &):
&
>>> 0x12345678 & 0xffff 22136 >>> hex(_) '0x5678'
您可以使用数组
array.array('H', [10])
将创建 1 个无符号短字的数组。(几年前,我用 Python 编写了一个结合数组和结构的硬件驱动程序