summaryrefslogtreecommitdiff
path: root/1241/CH2/EX2.49
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /1241/CH2/EX2.49
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '1241/CH2/EX2.49')
-rwxr-xr-x1241/CH2/EX2.49/exa2_49.sce40
1 files changed, 40 insertions, 0 deletions
diff --git a/1241/CH2/EX2.49/exa2_49.sce b/1241/CH2/EX2.49/exa2_49.sce
new file mode 100755
index 000000000..8214fff72
--- /dev/null
+++ b/1241/CH2/EX2.49/exa2_49.sce
@@ -0,0 +1,40 @@
+//Example 2-49//
+//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=38.21
+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 integer part of the binary form is :')
+disp(b)
+disp('the fractional part of the binary form is:')
+disp(s)
+//result is displayed//