I know how to convert from decimal to binary float.bit 31 = sign bit
bits 23 - 30 =biased exponent(single precision)
bits 0 - 22 = mantissa with implied leading 1.
Here is my dilemma.you convert the whole part as usual by repetitive division of the number by 2 and keeping record of the remainders. then writing the remainders out from right to left starting from the last one to the first one. there is also a subtraction method.
The fraction part is converted by multiplying the fraction part by 2 and writing the result of the whole part only,after each multipication until the fraction part becomes zero or you reach your precision target.
eg
70.25
[whole part] 70 = 01000110
[fraction part] 0.25 =>
0.25 * 2 = 0.5 so write 0 then use 0.5 for next loop/pass
0.50 * 2 = 1.0 so write 1 then stop as fract part is now zero
write binary fraction part starting from first to last
so 70.25 = 01000110.01
normalized 70.25 = 1.00011001 (we moved the point 6 places to the left so e = 6)
so in IEEE format
sign bit = 0
exponent = 10000101 (133 (6 +127(bias number))
mantisss = 00011001 (add trailing zero to complete 23 bits)
which gives
01000010100011001000000000000000 = 0X428C8000
How does one print Floats?
I was thinking of using tables of fractions [0.5,0.25,0.125,0.0625,0.03125] or [50000,25000,12500,6250,3125...]
but can see how.
Thanks