blob: 8a613eb8b70970bc825fca1d0a5f2e9f00cf0999 (
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
28
29
30
31
32
33
34
35
36
37
38
|
clear
//Initializaton
no=34.6875 //decimal number
n_int = int(no) // Extract the integral part
n_frac = no-n_int // Extract the fractional part
//Calculation
bini = 0
i = 1
ni = n_int
while (ni > 0)
rem = ni-int(ni/2)*2
ni = int(ni/2)
bini = bini + rem*i
i = i * 10
end
// Function to convert binary fraction to decimal fraction
binf = 0
i = 0.1,
nf = n_frac
while (nf > 0)
nf = nf*2
rem = int(nf)
nf = nf-rem
binf = binf + rem*i
i = i/10
end
//Result
printf("\n Decimal equivalent of 34.6875 = %.4f",(bini+binf))
|