Tony Grimer wrote: > > At 10:38 11/03/97 +0200, you wrote: > >I have been trying to figure out the way how Microchip has > >adopted the IEEE floating point math to their format they use in the > >pic 16 range. > >I have got the floating point math application notes which is fine if you > >know how to convert the answer back to legable values without > >using the float to int convertion routines. > >Can anyone give me help how to convert the 32 bit fp. to a > >understandable value and the other way arround aswell. > > IEEE 32 numbers are easy really if you understand the following > > The 32 bits are stored as > > 1 bit sign > 8 bits exponent > 23 Mantissa > > The mantissa is held in the range 1.0000--- 23 zeros in total > 1.1111--- 23 ones in total > > Notice the 1. is not stored because it is always present so you have to put > it back > > The exponent is held in biased 127 form.. this is to ensure it monotonic and > makes manipulation simpler. It is NOT a 2's complement number which is one > of the most common mistakes. > > The sign is the sign of the Number. So we can assume a Signed Magnitude overall. > > Thats a lot of words lets look at a simple example. > > If the 32 bits held > > 1 01111111 11000000000000000000000 > > Sign = 1 so number is negative > > Mantissa is 1.11000000000000000000000 We have added the 1. back... > > Biased Exponent is as unsigned value 127 > > So putting this together 1.11 x 2^ 127 -127 Note: remove the bias > > 1.11 x 2^0 > 1.11 x 1 > > In decimal this would be 1. 0.5+0.25 for the two '1's > 1.75 x 1 > The whole thing is negative so ANSWER is -1.75. > > Taking this the other way if we started with say the number > > 0.5 decimal > > Sign is positive so sign bit is a 0 > > Mantissa is 0.1 x 2^0 > > Normalise this to 1.0 x 2^-1 > > Bias the exponent so 2^-1 + 127 = 2^126 > > Mantissa 23 bits = 0000000000000000000000 the 1. is not stored. > > Exponent is 126 in binary 8 bits unsigned = 01111110 > > Final 32 bit are > 0 01111110 0000000000000000000000 > > Special cases .. Zero this is represented by 32 bits all at zero > > Since bias is 127 then value 255 in exponent can't occur > > Use this pattern i.e 11111111 to indicate limit conditions > > Negative Infinity is stored as Sign 1 - Exponent 11111111 mantissa 23 zero's > > Positive Infinity is stored as Sign 0 - Exponent 11111111 mantissa 23 ones's > > Hope this helps the algorithm is very straight forward really.. > > ---------------------------------------------------------------------------- > ---------- > Tony Grimer ---- cm1918@scitsc.wlv.ac.uk (Tony D. Grimer) > > School of Computing (SCIT) Room MU406 Tel - 01902-321810. > > ---------------------------------------------------------------------------- > ---------- DOH !!!!!!!!! system overload.... system overload..... system overload I'm just gona stick to INT's I think :))))))) -- Cheers Peter .......... ================================== New Ideas come from those who didn't know it wasn't possible ==================================