summaryrefslogtreecommitdiff
path: root/911/CH1/EX1.3/ex_1_3.sce
blob: 7915f24b6815a7770445b0aa0c1164d4f9936776 (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
// example 1.3//
clc
//clears the command window//
clear
//clears all the variables//
q =0;
b =0;
s =0;
// a=input (Enter the decimal no to be converted to its binary equivalent :) ;
//accepting the decimal input from user//
a =13.375;
d =modulo (a ,1) ;
//separating the decimal part and the integer part//
a = floor(a);
//removing the decimal part //
while (a>0)
//taking integer part into a matrix and convert to equivalent binary//
x=modulo (a ,2) ;
b=b +(10^q)*x ;
a = a/2;
a = floor(a) ;
q = q+1;
end
for i =1:10
// For values after decimal point converting to binary //
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 binary equivalent of the give decimal number is');
disp (k);
//displaying the final result//