Python Bitshift 32 位约束
这应该是一个相对简单的答案,我只是真的不知道如何搜索它......我得到了一些半相关的事情,但没有什么适合我想做的事情。
>>> 1171855803 << 7
149997542784L # I want -326312576
换句话说,将数字视为整数并且不允许其转换为长整型。 我该怎么做?
我尝试了这个问题中的解决方案:
>>> x = 0xFFFFFFFF & (1171855803 << 7)
>>> if x > 0x7FFFFFFF: print -(~(x - 1) & 0xFFFFFFFF)
else: print x
-326312576L # yay!
它有效!
Possible Duplicate:
Problem in calculating checksum : casting int to signed int32
This should be a relatively easy answer, I just don't really know how to search for it...I got a few semi-relevant things, but nothing that fits what I'm trying to do.
>>> 1171855803 << 7
149997542784L # I want -326312576
In other words, treat the number as an integer and don't allow it to convert to a long.
How would I do this?
I tried the solution in this question:
>>> x = 0xFFFFFFFF & (1171855803 << 7)
>>> if x > 0x7FFFFFFF: print -(~(x - 1) & 0xFFFFFFFF)
else: print x
-326312576L # yay!
It works!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能不是最好的答案,但这有效......
May not be the best answer, but this works...
您可以尝试
给出: c_int(-326312576)
它似乎允许平台特定的位操作。我不确定效率。
You could try
which gives: c_int(-326312576)
It seems to allow platform specific bit-manipulations. I am not sure about efficiency.