Skip to main content
1 of 3
Majenko
  • 105.5k
  • 5
  • 80
  • 138

You need to convert the format by overlaying one type on top of the other, rather than casting from one type to another.

1000 as an integer cast to a floating point value is still 1000.

You have an example of how it can be done in comments:

//float y = *(float*)&x;

However this method is called type punning and is frowned upon (there are compiler options that can prevent it being used). Instead using a union is a better option:

union ifloat {
    uint8_t bytes[4];
    float val;
};

void setup() {
    ifloat f;
    Serial.begin(115200);
    f.bytes[3] = 0x43;
    f.bytes[2] = 0x59;
    f.bytes[1] = 0xE1;
    f.bytes[0] = 0x89;
    Serial.println(f.val, 4);
    
}

void loop() {
}

So you can get the byte order right your current numeric value of 1129963913 is 0x4359E189 in hexadecimal. Byte 3 is therefore the most significant byte and byte 0 the least significant. Note that it can change from system to system depending on the endianness of the chip.

Majenko
  • 105.5k
  • 5
  • 80
  • 138