Hello,
Thanks to all your great contributions, I have succeeded to do what I wanted. Here is my code:
/*
Display Float Number under the Ieee 754 format
F. Auger, sept 2009
*/
void SerialPrintFloatIeee754(float RealNumber)
{
byte* ArrayOfFourBytes;
ArrayOfFourBytes = (byte*) &RealNumber;
if (ArrayOfFourBytes[3]>=128)
Serial.print("1 ");
else
Serial.print("0 ");
Serial.print((ArrayOfFourBytes[3]/64)%2, BIN);
Serial.print((ArrayOfFourBytes[3]/32)%2, BIN);
Serial.print((ArrayOfFourBytes[3]/16)%2, BIN);
Serial.print((ArrayOfFourBytes[3]/8)%2, BIN);
Serial.print((ArrayOfFourBytes[3]/4)%2, BIN);
Serial.print((ArrayOfFourBytes[3]/2)%2, BIN);
Serial.print( ArrayOfFourBytes[3]%2, BIN);
Serial.print((ArrayOfFourBytes[2]/128)%2, BIN);
Serial.print(" ");
Serial.print((ArrayOfFourBytes[2]/64)%2, BIN);
Serial.print((ArrayOfFourBytes[2]/32)%2, BIN);
Serial.print((ArrayOfFourBytes[2]/16)%2, BIN);
Serial.print((ArrayOfFourBytes[2]/8)%2, BIN);
Serial.print((ArrayOfFourBytes[2]/4)%2, BIN);
Serial.print((ArrayOfFourBytes[2]/2)%2, BIN);
Serial.print( ArrayOfFourBytes[2]%2, BIN);
Serial.print((ArrayOfFourBytes[1]/128)%2, BIN);
Serial.print((ArrayOfFourBytes[1]/64)%2, BIN);
Serial.print((ArrayOfFourBytes[1]/32)%2, BIN);
Serial.print((ArrayOfFourBytes[1]/16)%2, BIN);
Serial.print((ArrayOfFourBytes[1]/8)%2, BIN);
Serial.print((ArrayOfFourBytes[1]/4)%2, BIN);
Serial.print((ArrayOfFourBytes[1]/2)%2, BIN);
Serial.print( ArrayOfFourBytes[1]%2, BIN);
Serial.print((ArrayOfFourBytes[0]/128)%2, BIN);
Serial.print((ArrayOfFourBytes[0]/64)%2, BIN);
Serial.print((ArrayOfFourBytes[0]/32)%2, BIN);
Serial.print((ArrayOfFourBytes[0]/16)%2, BIN);
Serial.print((ArrayOfFourBytes[0]/8)%2, BIN);
Serial.print((ArrayOfFourBytes[0]/4)%2, BIN);
Serial.print((ArrayOfFourBytes[0]/2)%2, BIN);
Serial.println( ArrayOfFourBytes[0]%2, BIN);
return;
}
float x;
void setup()
{
Serial.begin(9600);
x = 1.50;
}
void loop()
{
Serial.print("x=");
SerialPrintFloatIeee754(x);
delay(2000);
}
This code is rather long, because the serial.print function does not print the leading useless zeros on the left, so I had to do it by myself.
Any advise to improve this code will be welcome.
Best regards,