Sunday, November 9, 2014

Sending single precision floating point over serial

Single Precision Float (32-bit) in IEEE754 standard
consist of sign bit(1 bit),exponent(8 bits) and fraction(23 bits)

http://upload.wikimedia.org/wikipedia/commons/thumb/e/e8/IEEE_754_Single_Floating_Point_Format.svg/2000px-IEEE_754_Single_Floating_Point_Format.svg.png

using typedef union for merge float,byte array into same location

typedef union {
 float floatingPoint;
 byte binary[4];
} binaryFloat;

binaryFloat temp;
temp.floatingPoint = 3.1416;
Serial.write(temp.binary[3]);
Serial.write(temp.binary[2]);
Serial.write(temp.binary[1]);
Serial.write(temp.binary[0]);

No comments:

Post a Comment