I have a situation in my application where the application is using a 128 bit integer (specifically, a __uint128_t
), and at some point the application needs to encode this 128 bit integer as two 64 bit integers (__uint64_t
).
(Just assume for the sake of this question that it must encode them like that -- this question is not about alternative ways to encode it)
How can I do this? I must be able to encode and decode.
void encode(__uint128_t src, __uint64_t &dest1, __uint64_t &dest2)
{
// ...
}
void decode(__uint64_t src1, __uint64_t src2, __uint128_t &dest)
{
// ...
}
Example usage:
__uint128_t bigIntBefore = 999999999999999999;
__uint64_t smallInt1;
__uint64_t smallInt2;
encode(bigIntBefore, smallInt1, smallInt2);
// ... later
__uint128_t bigIntAfter;
decode(smallInt1, smallInt2, bigIntAfter);
// bigIntAfter should have a value of '999999999999999999'