Skip to content

Instantly share code, notes, and snippets.

@RichardB01
Created May 28, 2020 16:19
Show Gist options
  • Save RichardB01/02846cd91d72160afef3f65fd6726887 to your computer and use it in GitHub Desktop.
Save RichardB01/02846cd91d72160afef3f65fd6726887 to your computer and use it in GitHub Desktop.
Function to combine two int32 into 1 int64.
static int64_t Pack(int32_t inX, int32_t inY)
{
int64_t x = static_cast<int64_t>(inX) << 32;
int64_t y = static_cast<int64_t>(inY);
// twos complement, therefore 32 msbs must be cleared.
if (inY < 0)
{
y = y ^ 0xFFFFFFFF00000000;
}
return x | y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment