如何将u8数组转换为u32?
例如:
u8 a[4];
u32 b;
a[0] = 0x00;
a[1] = 0x00;
a[2] = 0x00;
a[3] = 0x09;
如何将数组a(8bitx4 = 32bit)转换为b(32bit)?
答案 0 :(得分:-1)
unsigned char a[4];
unsigned int b;
a[0] = 0x00;
a[1] = 0x00;
a[2] = 0x00;
a[3] = 0x09;
int n = 1;
if (*(char *)&n == 1) {
std::reverse(std::begin(a), std::end(a));
}
b = *reinterpret_cast<unsigned int *>(&a);