Are you trying to receive an integer value to a float, or are you receiving the four bytes of a float variable, and trying to re-assemble them into a valid float value? Those are two completely different scenarios.
The c language include unions, in part, to provide a "clean" way to deal with this kind of issue. A union is the cleanest, safest way of handling the conversion (but it is still far from foolproof). The other method, using just a type cast, is quite unsafe, and will likely not work reliably. It may work on an AVR processor, but it certainly will not on some other processors. Try it on a Due, and I think you'll find it works sometimes, and not other. They union method will work on any processor.
I don't know what the internals of binToFloat look like, but I'd bet it uses a union.
RayLivingston:
If that is correct, then your solution with the union is the correct way to do it.
Regards,
Ray L.
Here's an actual example where I convert data (a generated waveform) into an output stream based on whether it's 8 bit, 16 bit, 32 bit or float using a union:
union { // wav data access as float, uint32 and individual bytes
uint8_t b[sizeof (float)]; // individual bytes
uint32_t i; // "input" as an int
float f; // "input" as a float
} data;
//.................
if (format == 1) {
data.i = accum; // put data in as integer
} else {
data.f = accum; // put data in as float
}
for (z = 0; z < channels; z++) {
for (y = 0; y < numbytes; y++) {
*outptr++ = data.b[y]; // write each byte to the buffer
}
}