【发布时间】:2009-06-17 17:41:38
【问题描述】:
这是为 MSVC 准备的
#define Get64B(hi, lo) ((((__int64)(hi)) << 32) | (unsigned int)(lo))
具体来说,'operator
感谢您的帮助
【问题讨论】:
-
谢谢你们。代码中使用的方式是从两个数字创建一个 unqiue id,就像大多数人所说的,两个 32 位数字。
这是为 MSVC 准备的
#define Get64B(hi, lo) ((((__int64)(hi)) << 32) | (unsigned int)(lo))
具体来说,'operator
感谢您的帮助
【问题讨论】:
【讨论】:
它接受两个32位整数并返回一个64位整数,第一个参数为高32位,第二个参数为低32位。
【讨论】:
operator
【讨论】:
AakashM 是正确的。写成方法可能更容易理解
__int64 Get64B(__int32 hi, __int32 lo) {
__int64 combined = hi;
combined = combined << 32; // Shift the value 32 bits left. Combined
// now holds all of hi on the left 32 bits
combined = combined | lo; // Low 32 bits now equal to lo
return combined;
}
【讨论】:
它将hi的值向左移动32位。
【讨论】:
这是左移运算符,其标准含义(对于数字类型)是向左移位
int a = 1;
int b = a << 3; // b is now 1000 binary, 8 decimal
代码从两个 32 位数字中创建一个 64 位数字。
【讨论】:
使用两个 32 位 int 返回一个 64 位 int,一个用作高位字节,第二个用作低位字节。
hi
Get64B (11111111111111110000000000000000, 00000000000000001111111111111111)
返回 1111111111111111000000000000000000000000000000001111111111111111
因为 11111111111111110000000000000000
1111111111111111000000000000000000000000000000000000000000000000
【讨论】:
返回两个 8、16、32 或 64 位整数的 64 位整数。 这更安全:hi
【讨论】: