Converting 4 raw bytes into 32-bit floating point

后端 未结 3 1241
有刺的猬
有刺的猬 2020-12-11 23:47

I\'m trying to re-construct a 32-bit floating point value from an eeprom.

The 4 bytes in eeprom memory (0-4) are : B4 A2 91 4D

and the PC (VS Studio) recon

3条回答
  •  不思量自难忘°
    2020-12-12 00:10

    The safest way, and due to compiler optimization also as fast as any other, is to use memcpy:

    uint32_t dword = 0x4D91A2B4;
    float f;
    memcpy(&f, &dw, 4);
    

    Demo: http://ideone.com/riDfFw

提交回复
热议问题