将两个十六进制变量合并为短

时间:2014-07-21 11:38:53

标签: c++ bit-manipulation

我有两个变量:

char a = "0xdb";
char b = "0x01";

如何将这些变量组合成短型?像这样:

short c = "0x01db";

感谢。

1 个答案:

答案 0 :(得分:2)

unsigned char a = 0xdb;
unsigned char b = 0x01;
unsigned short c = (b << 8) | a;