a float ? can anyone help?
Do the original 4 bytes make up a float ? Or is it something else ?
Yap its a original 32 bit float .
You should be able to use READSHORTIEEE in that case
+1
MrTAToad
If you're not reading this from a file, can you use an INLINE C++ Union? (Map the four bytes to a float).
I haven't programmed in C++ in 10+ years, no idea if this is an option, or even what you're looking for.
yap union and inline c are the right way.
thx
Not my code but here it is in C, two forms, one for each endianess.
float bytesToFloatA(uchar b0, uchar b1, uchar b2, uchar b3)
{
float output;
*((uchar*)(&output) + 3) = b0;
*((uchar*)(&output) + 2) = b1;
*((uchar*)(&output) + 1) = b2;
*((uchar*)(&output) + 0) = b3;
return output;
}
float bytesToFloatB(uchar b0, uchar b1, uchar b2, uchar b3)
{
float output;
*((uchar*)(&output) + 3) = b3;
*((uchar*)(&output) + 2) = b2;
*((uchar*)(&output) + 1) = b1;
*((uchar*)(&output) + 0) = b0;
return output;
}
float (*correctFunction)(uchar b0, uchar b1, uchar b2, uchar b3) = bytesToFloatA;
if ((*correctFunction)(0x3e, 0xaa, 0xaa, 0xab) != 1.f/3.f) // horrifying, I know
{
correctFunction = bytesToFloatB;
}
Should be quite easy to inline.
You just have to make sure the order is correct, otherwise might get the wrong value. You could also use memcpy if you know if the endianess doesn't change.