我有一段代码在 Javascript 中使用 32 位的值,我如何将其转换为 python,但按位给出的输出与 js 中的输出不同,我发现 python 使用 64 位和 js 32 位,我在 js 中有一些 var,比如 var t = [1116352408, 1899447441, 3049323471, ...
我认为它们是 32 位的,无论如何我知道如何通过这个函数截断到 32 位:
# numbits = 32 to truncate from 64-bit
def truncate(val, numbits):
return val & (2**numbits - 1)
我需要的例子是:
a, t = 5, 2
r = (a >> t | a << 32 - t) # r = 5368709121
j = truncate(r, 32) # j = 1073741825 this is the result I need
有没有办法做到这一点
v = untruncate(j, 64)
# v = 5368709121