I was going to convert a 0.1001ish binary into an array as part of an ieee single point conversion program. However, it has gotten the mantissa part incorrect and when checked using printf the result come up like this:
10 0.101010
0
11 1.010100
1
12 0.101000
0
13 1.010000
1
14 0.100000
0
15 1.000000
0
16 10.000000
9
17 90.000000
89
18 890.000000
889
19 8889.999999
8889
20 88889.999992
88889
21 888889.999916
888889
22 8888889.999156
8888889
23 88888889.991560
88888889
24 888888889.915602
888888889
25 8888888889.156019
-2147483648
26 88888888881.560196
-2147483648
27 888888888805.601930
-2147483648
28 8888888888046.019500
-2147483648
29 88888888880450.187000
-2147483648
30 888888888804491.870000
-2147483648
31 8888888888044909.000000
-2147483648
32 88888888880449088.000000
-2147483648
Btw this is my code(including the one used for checking
for(int i=10;i<=32;i++)
{
fraction=fraction*10;
printf("%d %lf\n",i,fraction);
checker=fraction*1;
printf("%d\n",checker);
if(fraction>=1)
{
fraction=fraction-1;
finalresult[i]='1';
}
else
{
finalresult[i]='0';
}
I dont understand why in number 15 the integer doesnt manage to get the 1 from the double.Would greatly appreciate help!