float转byte array

c语言float和bytes array转换

重点:大小端不要搞错 x86是小端,0x123456,对应4个字节,0x12,0x34,0x56,0x78. 在内存中的存储顺序是 0x78, 0x56, 0x34, 0x12 #include <stdio.h> int main(){ unsigned char buffer[] = {0x46, 0x87, 0x92, 0x64}; float a = 17353.195f; float b = 0; printf("zzzzz ....\n"); unsigned int* pa = (unsigned int*)(&a); unsigned int x = *pa; int x1 = (x >> 24) & 0xFF; int x2 = (x >> 16) & 0xFF; int x3 = (x >> 8) & 0xFF; int x4 = x & 0xFF; printf("%x",x1 ); printf("%x", x2); printf("%x", x3); printf("%x", x4); printf("\n"); un...
执行时间: 1716579010725.2 毫秒