If I have a uint64_t original and two regular four byte ints, (which are signed), I would like to store the value in the two ints and recover the unsigned 64 byte later. This should be possible because we have 64 bits available in both cases. I was thinking something along the lines of:
uint64_t test = 1350640807215539000;
int a = test >> 32; //get top 32 bits
int b = test & 0x00000000FFFFFFFF; //keep bottom 32 bits
uint64_t recover_test = ((a << 32) & b);
but this isn’t giving me back the original value of test…what part am I doing wrong?
Instead of doing a lot of error-prone bit-twiddling you could just use a union: