1.
u16 g_summ = 0;
u8 buf[2] = {0x10, 0x05};
g_summ = (buf[1] << 8) | buf[0]; // g_summ = 0x0510
2.
u16 g_summ = 0x0510;
buf[0] = (u8 )g_summ; // buf[0] = 0x10
buf[1] = (u8 )(g_summ >> 8); // buf[1] = 0x05
1.
u16 g_summ = 0;
u8 buf[2] = {0x10, 0x05};
g_summ = (buf[1] << 8) | buf[0]; // g_summ = 0x0510
2.
u16 g_summ = 0x0510;
buf[0] = (u8 )g_summ; // buf[0] = 0x10
buf[1] = (u8 )(g_summ >> 8); // buf[1] = 0x05
转载于:https://www.cnblogs.com/nxz-diy/p/10087124.html