diff options
Diffstat (limited to '1871/CH8/EX8.1/Ch08Ex1.sce')
-rwxr-xr-x | 1871/CH8/EX8.1/Ch08Ex1.sce | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/1871/CH8/EX8.1/Ch08Ex1.sce b/1871/CH8/EX8.1/Ch08Ex1.sce new file mode 100755 index 000000000..6313e7f4c --- /dev/null +++ b/1871/CH8/EX8.1/Ch08Ex1.sce @@ -0,0 +1,18 @@ +// Scilab code Ex8.1 : Pg:327(2008)
+clc;clear;
+function [dec]= binary_decimal(n) // Function to convert binary to decimal
+ dec = 0;
+ i = 0;
+ while (n <> 0)
+ rem = n-fix(n./10).*10;
+ n = int(n/10);
+ dec = dec + rem*2.^i;
+ i = i + 1;
+ end
+endfunction
+
+num = 11001; // Initialize the binary number
+printf("%d in binary = %d in decimal", num, binary_decimal(num));
+
+// Result
+// 11001 in binary = 25 in decimal
|