How to save 2 32-bit value in one long int variable? Is it possible?

I want to store two 32-bit values ​​in one long int variable. How do you do this on a 32-bit OS using C? Is it possible to store data in one long long variable? If so, how is this done?

+4
source share
3 answers

Assuming your platform is 64 bits long,

int v1 = 123; int v2 = 456; long val = v1 << 32 | v2; 
+1
source

Use uint64_t and bitwise operators.

 uint64_t i64; uint32_t a32, b32; // Be carefull when shifting the a32. // It must be converted to a 64 bit value or you will loose the bits // during the shift. i64 = ((uint64_t)a32 << 32) | b32; 
+8
source

If sizeof(long int) == 8 , the answer is no. If this equality is true, then use the answer of Kevin or cnicutar.

0
source

All Articles