Is it possible to store 2 32-bit values in one long int variable?

后端 未结 3 700
野性不改
野性不改 2020-12-21 05:18

I want to store two 32-bit values in a single long int variable.

How would you do this on a 32-bit OS using C? Is it possible to store the data in a single long long

3条回答
  •  甜味超标
    2020-12-21 05:56

    Use an 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;
    

提交回复
热议问题