如何在一个十六进制值中合并4个无符号char数组元素?

时间:2019-01-31 04:17:16

标签: c embedded embedded-linux

我有一个由4个元素组成的数组,类型为unsigned char。如何将它们合并为一个十六进制值?我需要将此值转换为IEE754值。

例如unsigned char arr[]={0x41,0xD9,0xD4,0x03}

预期o / p:0x41D9D403

1 个答案:

答案 0 :(得分:1)

unsigned long hex_val = ((unsigned long)arr[0] << 24) | ((unsigned long)arr[1] << 16) | ((unsigned long)arr[2] << 8) | ((unsigned long)arr[3]);