我有一个奇怪的结果来自一些大数学我不知道为什么我从vb.net和 python得到不同的答案. 这是快速片段和结果: VB.NETDim MSB As UInt32 = 3067297518Dim LSB As UInt32 = 1439785590Dim sqln As UInt64 = MSB * (2
这是快速片段和&结果:
VB.NET Dim MSB As UInt32 = 3067297518 Dim LSB As UInt32 = 1439785590 Dim sqln As UInt64 = MSB * (2 ^ 32) + LSB Python: sqln = msb * (2 ** 32) + lsb Python Result: 13173942528351756918 VB RESULT: 13173942528351756288
注意:我也尝试将sqln声明为ULong和Double(相同的答案)
MSB和LSB在两个调试器中都匹配 – !! ??
有任何想法吗?我的谢谢
杰出的乔恩 – 非常雄辩和优秀有用!
一个小小的跟进你可以建议最后一块的修复吗?即使你让我的sqln理顺了,我相信也会发生同样的事情:)
python says: = bdntyxtax2smq vb.net says: = bfpuzytbx3s00 VB.NET Dim sqlid As String = "" Dim alphabet As String = "0123456789abcdfghjkmnpqrstuvwxyz" For iCount = 0 To 12 sqlid = alphabet((sqln / (32 ^ iCount)) Mod 32) + sqlid Next Python: for i in range(0, 13): sqlid = alphabet[(sqln / (32 ** i)) % 32] + sqlid我已经将你的VB代码反编译为C#,它看起来像这样:
uint MSB = 0xb6d33eee; uint LSB = 0x55d16276; ulong sqln = (ulong) Math.Round((double) ((num2 * 4294967296) + num));
这是因为VB中的power operator总是返回一个Double:
The result is number raised to the power of exponent, always as a Double value.
我建议使用移位运算符,并将所有变量设为UInt64,以便将移位完成为64位整数:
Dim MSB As UInt64 = 3067297518 Dim LSB As UInt64 = 1439785590 Dim sqln As UInt64 = (MSB << 32) + LSB
这给出了正确的答案. (你实际上并不需要LSB成为UInt64,但你也可以用64位整数来做所有事情.)