两个字节合并为一个字(多种方法)
#define uint8 unsigned char#define uint16 unsigned int方法一:强制类型转换uint8 byte8_arry[2] = {0xAA,0xBB};uint16 word16 = *(uint16 *)byte8_arry;方法二:联合体typedef union{uint16 word16;uint8 byte8_arry[2];}word_byt
·
#define uint8 unsigned char
#define uint16 unsigned int
方法一:强制类型转换
uint8 byte8_arry[2] = {0xAA,0xBB};
uint16 word16 = *(uint16 *)byte8_arry;
方法二:联合体
typedef union{
uint16 word16;
uint8 byte8_arry[2];
}word_bytes;
word_bytes a;
a = 0xAABB;
方法三:移位
uint8 byte8_arry[2]={0xAA,0xBB};
uint16 word16 = byte8_arry[0]<<8 + byte8_arry[1];
更多推荐
已为社区贡献2条内容
所有评论(0)