If you do indeed have an ASCII string of hexadecimal numbers (and not a
raw binary float), then your best option may be to do the conversion in
two steps:
- convert the string to a 32 bit unsigned number using
strtoul()
- reinterpret the binary pattern of this integer as a float.
For example, the following program:
void setup() {
const char modbus_data[] = "416F0000";
union {
uint32_t i;
float f;
} data;
data.i = strtoul(modbus_data, NULL, 16);
Serial.begin(9600);
Serial.println(data.f, 4);
}
void loop(){}
prints 14.9375.
Note that for strtoul() to function properly, the hex string must be
followed by a character that is not a valid hex digit (a \0 in the
example above).