diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /1646/CH15/EX15.7 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '1646/CH15/EX15.7')
-rwxr-xr-x | 1646/CH15/EX15.7/Ch015Ex7.sce | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/1646/CH15/EX15.7/Ch015Ex7.sce b/1646/CH15/EX15.7/Ch015Ex7.sce new file mode 100755 index 000000000..71874555a --- /dev/null +++ b/1646/CH15/EX15.7/Ch015Ex7.sce @@ -0,0 +1,31 @@ +// Scilab code Ex15.7 : Pg:773(2011)
+clc;clear;
+function [bini]= decimal_binary(ni) // Function to convert decimal to binary
+ bini = 0;
+ i = 1;
+ while (ni <> 0)
+ rem = ni-fix(ni./2).*2;
+ ni = int(ni/2);
+ bini = bini + rem*i;
+ i = i * 10;
+ end
+endfunction
+
+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
+
+num1 = 11101; // Initialize the first binary number
+num2 = 10111; // Initialize the second binary number
+
+printf("%6d + %6d = %7d", num1, num2, decimal_binary(binary_decimal(num1)+binary_decimal(num2)));
+
+// Result
+// 11101 + 10111 = 110100
|