summaryrefslogtreecommitdiff
path: root/243/CH3/EX3.5/3_05.sce
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /243/CH3/EX3.5/3_05.sce
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 '243/CH3/EX3.5/3_05.sce')
-rwxr-xr-x243/CH3/EX3.5/3_05.sce33
1 files changed, 33 insertions, 0 deletions
diff --git a/243/CH3/EX3.5/3_05.sce b/243/CH3/EX3.5/3_05.sce
new file mode 100755
index 000000000..53d61068c
--- /dev/null
+++ b/243/CH3/EX3.5/3_05.sce
@@ -0,0 +1,33 @@
+//Example No. 3_05
+//Decimal to binary
+//Pg No. 48
+clear ; close ; clc ;
+
+d = 0.65
+j = 1 ;
+
+while d ~= 0
+ fracp(j) = floor(d*2) //integral part of d*2
+ d = d*2 - floor(d*2) //Fractional part of d*2
+ j = j+1 ;
+ decp(j-1) = d
+ p = 1
+
+ for i = 1:j-2
+ if abs(d - decp(i))< 0.001 then //Condition for terminating the recurring binary equivalent by
+ p = 0 //finding out if the new fractional part is equal to any of the previous fractonal parts
+ break
+ end
+ end
+
+ if p == 0 then
+ break
+ end
+
+end
+rec_p = fracp(i+1:j-1) //Recurring part
+
+rec_p = strcat(string(rec_p))
+fracp = strcat(string(fracp))
+
+disp(strcat( [fracp,rec_p] ),'Binary equivalent = ')