Binary To Decimal
Binary To Decimal
int main()
{
return 0;
}
if (i==n)
return b[n];
//base
case
else
return 2*horner(b,i+1,n)+b[i];
}
Hex to decimal
d=hex[i]-'0';
if (i==n)
return d;
else
return 16*horner(hex,i+1,n)+d;
}
11
else
d=hex[n]-'0';
if (n==0)
return d;
else
return 16*horner(hex,n-1)+d;
}
13
15
Binary equivalent of .1
2 x .1 =.2
integer part =0
2 x .2 =.4
integer part =0
2 x .4 =.8
integer part =0
2 x .8 =1.6
integer part =1
2 x .6=1.2
integer part =1
2 x .2 =.4
integer part =0
error-Look at http://www.ima.umn.edu/~arnold/disasters/patriot.html
To find out why this was once very important.
17
double frac=.1;
int digits=1,intpart;
cout <<".";
while (digits <32 && frac!=0.)
{
frac=frac*2;
intpart=frac;
frac=frac-intpart;
cout <<intpart;
digits++;
}
18
Output: .0001100110011001100110011001100
19
}21