blob: 8bda2fe42f8cb35d8afee1747dab3ae3d16e8dcd (
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
|
// 9.12
clc;
q =0;
b =0;
s =0;
a =0.6875; // accepting the decimal input from user
d = modulo (a ,1) ;
a = floor ( a ) ;
while (a >0)
x = modulo (a ,2) ;
b = b + (10^ q ) * x ;
a = a /2;
a = floor ( a ) ;
q = q +1;
end
for i =1:10
// for fractional part
d = d *2;
q = floor ( d ) ;
s = s + q /(10^ i ) ;
if d >=1 then
d =d -1;
end
end
m=b+s;
printf("Equivalent binary number=%.4f",m)
|