c++ - Converting 4 raw bytes into 32-bit floating point -



c++ - Converting 4 raw bytes into 32-bit floating point -

i'm trying re-construct 32-bit floating point value eeprom.

the 4 bytes in eeprom memory (0-4) : b4 a2 91 4d

and pc (vs studio) reconstructs correctly 3.054199 * 10^8 (the floating point value know should there)

now i'm moving eeprom read 8-bit arduino, not sure if it's compiler/platform thing, when seek reading 4 bytes 32-bit dword, , typecast float, value isn't close.

assuming conversion can't done automatically standard ansi-c compiler, how can 4 bytes manually parsed float?

the safest way, , due compiler optimization fast other, utilize memcpy:

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

demo: http://ideone.com/ridffw

c++ c floating-point floating-point-conversion

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -