Assuming a low end microprocessor with no floating point arithmetic, I need to generate an IEE754 single precision floating point format number to push out to a file.
I need to write a function that takes three integers being the sign, whole and the fraction and returns a byte array with 4 bytes being the IEEE 754 single precision representation.
Something like:
// Convert 75.65 to 4 byte IEEE 754 single precision representation
char* float = convert(0, 75, 65);
Does anybody have any pointers or example C code please? I'm particularly struggling to understand how to convert the mantissa.
The basic premise is to:
float
.whole
and factional partshundredths
. This code uses a structure encoding both whole and hundredths fields separately. Important that thewhole
field is at least 32 bits.whole, hundredths
input, generating thosefloat
special cases are not addressed here..
Output
Known issues: sign not applied.