如何在c ++中将2个数字存储到32位数字中

时间:2017-06-19 04:46:05

标签: c++ c++11

我有两个整数,我想将它们放入一个32位数字,这样0到16的第一位将用于第一个数字,17到32个其他位用于另一个数字。怎么做这个工作?

1 个答案:

答案 0 :(得分:0)

int32_t i32 = (int32_t)( (uint32_t)s1<<16 | (uint32_t)s2 );

另见Cleanest way to combine two shorts to an int