summaryrefslogtreecommitdiff
path: root/2825/CH19/EX19.9/Ex19_9.sce
blob: e2ba6879061826c9c6ea1cbc9811f5d127090dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//Ex19_9 Pg-960
clc
disp("Conversion of decimal number 31.65 base to its binary equivalent ")
a=31.65;
z=modulo(a,1)
x=floor(a);//separating the decimal from the integer part
b=0;
c=0;
d=0;
while(x>0)  //taking integer part into a matrix and convert to equivalent binary
y=modulo(x,2);
b=b+(10^c)*y;
x=x/2;
x=floor(x);
c=c+1;
end
for i=1:10;//converting the values after the decimal point into binary
    z=z*2;
    q=floor(z);
    d=d+q/(10^i);
    if z>=1 then
        z=z-1;
    end
end
s=b+d;
printf("\n               =%.6f",s);