summaryrefslogtreecommitdiff
path: root/243/CH4/EX4.3
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /243/CH4/EX4.3
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/CH4/EX4.3')
-rwxr-xr-x243/CH4/EX4.3/4_03.sce29
1 files changed, 29 insertions, 0 deletions
diff --git a/243/CH4/EX4.3/4_03.sce b/243/CH4/EX4.3/4_03.sce
new file mode 100755
index 000000000..74c85ffca
--- /dev/null
+++ b/243/CH4/EX4.3/4_03.sce
@@ -0,0 +1,29 @@
+//Example No. 4_03
+//Pg No. 64
+clear ; close ; clc ;
+
+a = 0.1
+b = 0.4
+for i = 1:8
+ afrac(i) = floor(a*2)
+ a = a*2 - floor(a*2)
+ bfrac(i) = floor(b*2)
+ b = b*2 - floor(b*2)
+end
+afrac_s = '0' + '.' + strcat(string(afrac)) //string form binary equivalent of a i.e 0.1
+bfrac_s = '0' + '.' + strcat(string(bfrac))
+mprintf('\n 0.1_10 = %s \n 0.4_10 = %s \n ', afrac_s , bfrac_s)
+for j = 8:-1:1
+ summ(j) = afrac(j) + bfrac(j)
+ if summ(j) > 1 then
+ summ(j) = summ(j)-2
+ afrac(j-1) = afrac(j-1) + 1
+ end
+end
+summ_dec = 0
+for k = 8:-1:1
+ summ_dec = summ_dec + summ(k)
+ summ_dec = summ_dec*1/2
+end
+disp(summ_dec,'sum =')
+disp('Note : The answer should be 0.5, but it is not so.This is due to the error in conversion from decimal to binary form.') \ No newline at end of file