我正在尝试将 2 个 unsigned char 保存到一个 unsigned short 中。所以我所做的是保存第一个字符,然后将其移位或使用第二个字符。
代码:
unsigned char a = 8;
unsigned char b = 2;
unsigned short c = a;
c << 8;
c |= b;
但是我首先遇到了位移问题。运行此代码:
unsigned char a = 8;
unsigned short c = a;
c << 8;
cout << c;
我希望得到 2048。我什至在这里检查过:http: //www.miniwebtool.com/bitwise-calculator/bit-shift/ ?data_type=10&number=8&place=8&operator=Shift+Left 。但相反,我得到了 8。我做错了什么?