I do not understand the need for scaling, since the exponents and scales are almost the same.
you can find the IEEE Floats specification used by C. implementations, so you can save your value in the float by typing it in uint32 and extract information about the sign, exponent and mantissa from it and pack it in a smaller format.
float val = 234.323f; uint32_t valB = ((uint32_t*)(&val)); uint32_t signBit = valB >> 31; uint32_t exp = (valB >> 23) & 0xff; uint32_t mant = valB & 0x7FF;
You now have separate components. save them in your data with the necessary degree of accuracy and vice versa.
One caveat: exp is stored at offset 128, so you have to transfer it back to the signed one and save it with another offset that suits your requirements.
http://de.wikipedia.org/wiki/IEEE_754#Zahlenformate_und_andere_Festlegungen_des_IEEE-754-Standards (look at the color image)
edit: according to your needs you can reset bits from the mantissa to a minimum without any problems (but you may want to round if bit 1 is set) and you need to separate 2 bits from the exponent.
uint32_t smallMant = mant>>2; int32_t realExp = ((int32_t)exp) - 128; uint32_t smallExp = realExp + 32; uint32 reducedData28 = (signBit << 27) | (smallExp << 21) | smallMant;
If the indicator of the desired range is not symmetrical, you can choose a different offset than half the possible range.
source share