I think you _could_ be making it much more complicated than it actually is. The reasoning behind it may be complicated, but the application of it is not -- It is rather simple.
I got interested since I have never actually tried. So I googled and found:
http://www.keil.com/support/man/docs/c5 ... tingpt.htm
Then I noticed the basic concept for a 32 bit scalar or FLOAT in C using the IEEE-754 standard is that the lower 24 bits or bit 0 - 23 is the mantissa which has a complicated meaning of course but is rather simple as part of the application. The next 8 bits are the exponet. As far as I can tell the mantissa is multiplied by 2 raised to the power of the exponet... but I think the rest of the explanation can be found which of course is better explained than by me with in the link above.
Here is the code I _just_ wrote, and actually enjoyed doing so. I now know how to do this.
Code: Select all
float f = 125.26;
// Reference the memory of the float varible.
unsigned int *u = (unsigned int*)&f;
// The mantissa is the least significant 24 bits.
unsigned int mana = (*u & 0x007FFFFF);
// Trying to grab the 8 bits starting at the bit 30 and moving down.
int exponet = ((*u & 0x7F800000) >> 23) - 127;
// The sign is stored in bit 31.
unsigned int sign = *u >> 31;
unsigned int wholenumber, fractional;
// mana is expected to be "1.mana"
printf("[%u,%d,%u]\n", mana, exponet, sign);
// I move the entire 23 bits snug up to the 31st bit.
// I set the 31st bit to 1 with 0x80000000 to repersent the 1.mana
// I think slide it back and then move the entire mana below bit 0 with >> 8+23
// Then I slide it back to the left with -exponet to have only the whole number
// bits revealed, and ofcourse I store them.
wholenumber = ((mana << 8) | 0x80000000) >> (8 + 23 - exponet);
// Any bits not used in wholenumber are fractional.
fractional = mana << (9 + exponet) >> (9 + exponet);
// Display the parts.
printf("sign:%u whole: %u fractional: %u\n", sign, wholenumber, fractional);
But where could I find one? I don't know any good keywords to google.
What in the world do you mean, "good keywords". Is google supposed to be the lottery where you get lucky, its more like you use some common sense.
GOOGLE:
floating point number storage format... ::)