两个字节合并为一个字(多种方法)

文章目录

#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]; 
    原文作者:taotianlucky
    原文地址: https://blog.csdn.net/qq_31020665/article/details/115760410
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞