I'm pretty sure its just a matter of some bitwise operations, I'm just not entirely sure of exactly what I should be doing, and all searches return back "64 bit vs 32 bit".
A 32 bit Signed Integer can house a number from −2,147,483,648 to 2,147,483,647 Unsigned: 0 to 4,294,967,295. A 64 bit Signed Integer can house a number from −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Unsigned: 0 to 18,446,744,073,709,551,615.
Similarly, if you want to use 16 bits, 32 bits, and 64 bits to store integers, the ranges would be: 16-bits ~ [-215, 215 – 1] = [ -32,768 , 32,767 ] 32-bits ~ [-231, 231 – 1] = [- 2,147,483,648 , 2,147,483,647 ] 64-bits ~ [-263, 263 – 1] = [ -9,223,372,036,854,775,808 , 9,223,372,036,854,775,807 ]
int is 32 bits in size. long , ptr , and off_t are all 64 bits (8 bytes) in size.
pack:
u32 x, y; u64 v = ((u64)x) << 32 | y;
unpack:
x = (u32)((v & 0xFFFFFFFF00000000LL) >> 32); y = (u32)(v & 0xFFFFFFFFLL);
Or this, if you're not interested in what the two 32-bits numbers mean:
u32 x[2]; u64 z; memcpy(x,&z,sizeof(z)); memcpy(&z,x,sizeof(z));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With