summaryrefslogtreecommitdiff
path: root/1241/CH2/EX2.48/exa2_48.sce
blob: 13971ef2067f4a5993e49137cae1847ff3c2c0c0 (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
//Example 2-48//
//Conversion of decimal to binary//
clc
//clears the console//
clear
//clears all existing variables//
q=0
b=0
s=0
//initialising//
//a=input(enter the decimal number to be converted to its binary form)
//taking input from the user//
a=0.54545
d=modulo(a,1)
//separating the decimal part from the integer//
a=floor(a)
//removing the decimal part//
while(a>0)
//integer part converted to equivalent binary form//  
x=modulo(a,2)
b=b+(10^q)*x
a=a/2
a=floor(a)
q=q+1
end
for i=1: 10
//taking values after the decimal part and converting to equivalent binary form//
d=d*2
q=floor(d)
s=s+q/(10^i)
if d>=1 then
    d=d-1
end
end
k=b+s
disp('the decimal number in binary form is :')
disp(k)
//result is displayed//