summaryrefslogtreecommitdiff
path: root/1332/CH1/EX1.1/1_1.sce
diff options
context:
space:
mode:
Diffstat (limited to '1332/CH1/EX1.1/1_1.sce')
-rwxr-xr-x1332/CH1/EX1.1/1_1.sce34
1 files changed, 34 insertions, 0 deletions
diff --git a/1332/CH1/EX1.1/1_1.sce b/1332/CH1/EX1.1/1_1.sce
new file mode 100755
index 000000000..e8854653d
--- /dev/null
+++ b/1332/CH1/EX1.1/1_1.sce
@@ -0,0 +1,34 @@
+//Example 1.1
+//Conversion to Decimal System
+//Page no. 4
+clc;close;clear;
+function [s]=bas2dec(x,b)
+ xi=int(x)
+ xd=x-int(x)
+ s=0
+ for i=1:10
+ xi=xi/10
+ s=s+(10*(xi-fix(xi))*b^(i-1))
+ xi=int(xi)
+ if(xi==0)
+ break
+ end
+ end
+ for i=1:1
+ xd=xd*10;
+ s=s+(ceil(xd)/b^(i))
+ xd=xd-fix(xd)
+ if(xd==0)
+ break
+ end
+ end
+endfunction
+
+//conversion from hexadecimal to decimal system
+disp(hex2dec('1A2C'),'1A2C='); //inbuit function
+
+//conversion from hexadecimal to decimal system
+disp(bas2dec(428.5,8),'428.5=') //inline function
+
+//conversion from hexadecimal to decimal system
+disp(bas2dec(120.1,3),'120.1=') //inline function \ No newline at end of file