C 合并三个小口

C 合并三个小口,c,C,我正在编写一个结合半字节的代码。我有一个工作,我结合两个小口。但是,我还需要将三个半字节合并为一个12位。有人知道怎么做吗?谢谢 例如: 小口1:F 小口2:1 小口3:3 结果是F31 编辑: 正如其他人所要求的,这是我的两个半字节组合器: unsigned int combineBytes(unsigned lowByte, unsigned highByte){ unsigned int combinedByte; combinedByte = lowByte | (hig

我正在编写一个结合半字节的代码。我有一个工作,我结合两个小口。但是,我还需要将三个半字节合并为一个12位。有人知道怎么做吗?谢谢

例如:

小口1:F

小口2:1

小口3:3

结果是F31

编辑: 正如其他人所要求的,这是我的两个半字节组合器:

unsigned int combineBytes(unsigned lowByte, unsigned highByte){
    unsigned int combinedByte;
    combinedByte = lowByte | (highByte << 4);
    return (combinedByte);
} 
无符号整数组合字节(无符号低字节、无符号高字节){
无符号整数组合字节;
combinedByte=lowByte |(highByte
int8u半字节1=0xF;
int8u半字节2=0x1;
int8u半字节3=0x3;
int16u组合;

combled=(一点一点地)你是如何将两个一点地结合起来的,你在尝试将其扩展到三个一点时遇到了什么问题?为什么我在读这个问题时会想到索科班@alk从来没有听说过Sokoban,直到你提到它。@user2989964:@alk很有趣。我可能在童年时玩过它。谢谢!真不敢相信我错过了这个。我猜我有心理障碍!只是想检查一下,答案应该是F31,对吗?就像我有的一样?F是最左边的,有8位移位。1在最右边,没有位移位,3在第e中间有4位移位。我理解对了吗?谢谢!int8u
从哪里来?@alk.And.但找不到任何常见的.h文件,包括int8u。可能使用了很多(通过使用基本类型定义)在固件或嵌入式工作中。@Ryker你说得对。我现在正在开发的嵌入式微控制器是STM32。我们使用
typedef unsigned char int8u;
来定义
int8u
。在嵌入式应用程序中,了解位宽度非常重要。
int8u nibble1 = 0xF;
int8u nibble2 = 0x1;
int8u nibble3 = 0x3;
int16u combined;

combined = (nibble1 << 8) | (nibble2) | (nibble3 << 4);