1. uint8_t 转uint16_t
uint8_t u8[4] = {0x12,0x34,0x56,0x78};
uint16_t u16[2] = {0};
u16[0] = (u8[1] << 8) + u8[0];
u16[1] = (u8[3] << 8) + u8[2];
2. uint8_t 转uint32_t
uint8_t u8[4] ={0x12,0x34,0x56,0x78};
uint32_t u32 = 0;
u32 = (u8[3] << 24) + (u8[2] << 16) + (u8[1] << 8) + u8[0];
3. uint16_t 转uint8_t
uint8_t u8[4] = {0};
uint16_t u16[2] = {0x3412,0x7856};
u8[0] = u16[0] & 0xFF;
u8[1] = (u16[0] >> 8) & 0xFF;
u8[2] = u16[1] & 0xFF;
u8[3] = (u16[1] >> 8) & 0xFF;
4. uint16_t 转uint32_t
uint16_t u16[2] = {0x1234,0x5678};
uint32_t u32 = 0;
u32 = (u16[1] << 16) + u16[0];
5. uint32_t 转uint8_t
uint8_t u8[4] ={0};
uint32_t u32 = 0x78563412;
u8[0] = u32 & 0xFF;
u8[1] = (u32 >> 8) & 0xFF;
u8[2] = (u32 >> 16) & 0xFF;
u8[3] = (u32 >> 24) & 0xFF;
6. uint32_t 转uint16_t
uint8_t u16[2] ={0};
uint32_t u32 = 0x56781234;
u16[0] = u32 & 0xFFFF;
u16[1] = (u32 >> 16) & 0xFFFF;