fnsnoop:
I am outputting the value of the float as hex and I do not understand the last 2 bytes. A1:10:51:C0:0D:0A. It should be just A1:10:51:C0. Maybe this is not right "(char *)&number"?float number = -3.26664;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println((char *)&number);
delay(1000);
}
What you are doing there is called 'type punning' but you're doing it the wrong way. The right way is to use a union:
union floatUIntUnion {
float fl;
uint32_t u32;
uint8_t u8q[4];
};
floatUIntUnion fiu;
float flibble=50509.324;
fiu.fl=flibble;
Serial.println(fiu.u32,HEX);
//Serial.write(fiu.u8q,4); //to write bytes
uint32_t someNumberIEEE754=0x40490FDB;
fiu.u32=someNumberIEEE754;
Serial.println(fiu.fl,7);
Google 'C++ union' and 'type punning' to find out more ![]()