注册 登录
编程论坛 C语言论坛

4个8位的低4位,如何拼成一个16位?

szchen2018 发布于 2021-12-31 18:09, 1885 次点击

比如:
uint8_t temp [20] ={0};
uint16_t temp2 = 0;
temp[0]=0x01; temp[1]=0x0F; temp[2]=0x1B;temp[3]=0x29;
怎么合并成为temp2 =0x9BF1;
2 回复
#2
apull2021-12-31 22:20
程序代码:

for(int i=3;i>=0;i--)
{
    temp2 |=(temp[i] & 0xF) << (4*i);        
}  


[此贴子已经被作者于2021-12-31 22:23编辑过]

#3
szchen20182022-01-03 21:03
回复 2楼 apull
谢谢!
1