This is for MSVC
#define Get64B(hi, lo) ((((__int64)(hi)) << 32) | (unsigned int)(lo))
Specifically, what is the role of the 'operator <<' ?
Thanks for your help
This is for MSVC
#define Get64B(hi, lo) ((((__int64)(hi)) << 32) | (unsigned int)(lo))
Specifically, what is the role of the 'operator <<' ?
Thanks for your help
<< is the left shift operator. This macro is intended to make a 64-bit value from two 32 bit values, using the first argument as the top 32 bits and the second argument as the bottom 32 bits of the new value.
It takes two 32 bit integers and returns a 64 bit integer, with the first parameter as the 32 high bits and the second as the 32 low bits.
<< is the left shift operator. It takes the high 32 bits, shifts them over, and then ORs the that result with the low bits.
operator << is a binary left shift operator. It shifts the int64 variable hi left by 32 bits.
That's the left shift operator, and its standard meaning (for number types) is shifting bits to the left
int a = 1;
int b = a << 3; // b is now 1000 binary, 8 decimal
The code creates a 64 bit number out of two 32 bit numbers.
AakashM is correct. It may be easier to understand written as a method
__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;
}
That returns a 64 bit int using two 32 bit int, one is used as de hi order bytes and the second one as the low order bytes.
hi << 32 converts the integer to the high order bytes of the 64 bit int. Example:
Get64B (11111111111111110000000000000000, 000000000000000011111111111111111)
returns 11111111111111110000000000000000000000000000000011111111111111111
Because 11111111111111110000000000000000 << 32 returns
1111111111111111000000000000000000000000000000000000000000000000
Return a 64-bits integer of two 8,16,32 or 64-bits integers. This safer as: hi << 32 | lo