diff options
Diffstat (limited to '1241/CH3/EX3.3/exa3_3.sce')
-rwxr-xr-x | 1241/CH3/EX3.3/exa3_3.sce | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/1241/CH3/EX3.3/exa3_3.sce b/1241/CH3/EX3.3/exa3_3.sce new file mode 100755 index 000000000..9feb4c56c --- /dev/null +++ b/1241/CH3/EX3.3/exa3_3.sce @@ -0,0 +1,40 @@ +//Example 3-3//
+//add 3 and 2 in Excess 3 code//
+clc
+//clears the console//
+clear
+//clears all existing variables//
+n=3
+m=2
+z=0
+a=0110
+b=0101
+ea=dec2bin(n+3)
+eb=dec2bin(m+3)
+for i=1: 4
+ x(i)=modulo(a,10)
+ a=a/10
+ a=floor(a)
+ y(i)=modulo(b,10)
+ b=b/10
+ b=floor(b)
+end
+for i=1: 4
+ g(i)=bitand(x(i),y(i))
+ p(i)=bitor(x(i),y(i))
+end
+c(1)=0
+for i=1: 4
+ c(i+1)=bitor(g(i),bitand(p(i),c(i)))
+end
+if c(5)==1 then
+ z=dec2bin(bin2dec(ea)+bin2dec(eb)+3)
+end
+if c(5)==0 then
+ z=dec2bin(bin2dec(ea)+bin2dec(eb)-3)
+end
+disp('equivalent binary number after excess 3 addition' )
+disp(z)
+disp('equivalent decimal number')
+disp(m+n)
+//result is displayed//
|