[Solved] float to embedded c float over UART [closed]


You cannot convert an integer bitpattern to a float by means of a cast. That just converts the integer to the nearest floating-point number, it does not re-interpret the bits as being a float. If it worked like you think, this:

const float x = 512;

would set x to 7.175E-43, which would not be very convenient.

The best way is probably to just copy the bits, so replace

SUS_Data.Longitude = ((float)Longitude);

by:

memcpy(&SUS_Data.Longitude, &Longitude, sizeof SUS_Data.Longitude);

solved float to embedded c float over UART [closed]