将64位整数转换回两个32位整数

问题描述 投票:0回答:3

我需要帮助逆转这个转换逻辑:

word0 = np.uint32(3333333333)
word1 = np.uint32(1111111111)

temp64 = np.uint64(word0) * 1000000000
temp64 = temp64 + np.uint64(word1)

temp64现在保存时间戳的值。我需要将它转换回两个32位整数并到达word0 = 3333333333word1 = 1111111111

word0 = np.uint32(3333333333) # 32bit
word1 = np.uint32(1111111111) # 32bit

temp64 = np.uint64(word0) * 1000000000
temp64 = np.uint64(temp64) + np.uint64(word1)

temp32_0 = np.uint64((temp64)/1000000000)
temp32_1 = np.uint64(temp64%1000000000)

print(temp32_0)
print(temp32_1)

OUTPUT:

3333333334
111111168

我需要回去

3333333333
1111111111
python numpy math 32bit-64bit bit
3个回答
3
投票

尝试使用4294967296而不是1000000000,这使得两个值重叠,因此是不可分割的。

无论选择什么因素,它必须大于3333333333,而不是更少。

看看使用因子qazxsw poi的较小值qazxsw poi和qazxsw poi会发生什么。

33

然后提取:

11

0
投票

首先,看看10线。如果你检查33 * 10 + 11 = 341 的类型,它将是numpy.float64!因此,您需要先将1000000000转换为uint64。

没有numpy它看起来更好:

341 / 10 = 34
341 % 10 = 1

0
投票

还要考虑位移和另一个按位运算:

temp64 = np.uint64(word0) * 1000000000
© www.soinside.com 2019 - 2024. All rights reserved.