summaryrefslogtreecommitdiff
path: root/1871/CH8/EX8.3
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /1871/CH8/EX8.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 '1871/CH8/EX8.3')
-rwxr-xr-x1871/CH8/EX8.3/Ch08Ex3.sce32
1 files changed, 32 insertions, 0 deletions
diff --git a/1871/CH8/EX8.3/Ch08Ex3.sce b/1871/CH8/EX8.3/Ch08Ex3.sce
new file mode 100755
index 000000000..8862781e3
--- /dev/null
+++ b/1871/CH8/EX8.3/Ch08Ex3.sce
@@ -0,0 +1,32 @@
+// Scilab code Ex8.3 : Pg:328(2008)
+clc;clear;
+function [deci]= binary_decimal(ni) // Function to convert binary to decimal
+ deci = 0;
+ i = 0;
+ while (ni <> 0)
+ rem = ni-fix(ni./10).*10;
+ ni = int(ni/10);
+ deci = deci + rem*2.^i;
+ i = i + 1;
+ end
+endfunction
+
+function [decf]= binfrac_decifrac(nf) // Function to convert binary fraction to decimal fraction
+ decf = 0;
+ i = -1;
+ while (i >= -3)
+ nf = nf*10;
+ rem = round(nf);
+ nf = nf-rem;
+ decf = decf + rem*2.^i;
+ i = i - 1;
+ end
+endfunction
+
+n = 101.101; // Initialize the binary number
+n_int = int(n); // Extract the integral part
+n_frac = n-n_int; // Extract the fractional part
+printf("Decimal equivalent of %7.3f = %5.3f", n, binary_decimal(n_int)+binfrac_decifrac(n_frac));
+
+// Result
+// Decimal equivalent of 101.101 = 5.625