fadini
fadini

Reputation: 125

what does this C++ macro do?

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

Upvotes: 1

Views: 1214

Answers (8)

bill
bill

Reputation: 1361

Return a 64-bits integer of two 8,16,32 or 64-bits integers. This safer as: hi << 32 | lo

Upvotes: -1

albertein
albertein

Reputation: 27120

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

Upvotes: 0

JaredPar
JaredPar

Reputation: 754515

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;
}

Upvotes: 2

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 506837

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.

Upvotes: 0

Soo Wei Tan
Soo Wei Tan

Reputation: 3371

It bit shifts the value of hi to the left by 32 bits.

Upvotes: 0

stanigator
stanigator

Reputation: 10926

operator << is a binary left shift operator. It shifts the int64 variable hi left by 32 bits.

Upvotes: 2

FreeMemory
FreeMemory

Reputation: 8614

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.

Upvotes: 3

AakashM
AakashM

Reputation: 63340

<< 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.

Upvotes: 17

Related Questions