diff options
Diffstat (limited to '275/CH8/EX8.8.31a')
-rwxr-xr-x | 275/CH8/EX8.8.31a/Ch8_8_31a.sce | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/275/CH8/EX8.8.31a/Ch8_8_31a.sce b/275/CH8/EX8.8.31a/Ch8_8_31a.sce new file mode 100755 index 000000000..bc5abac67 --- /dev/null +++ b/275/CH8/EX8.8.31a/Ch8_8_31a.sce @@ -0,0 +1,43 @@ +clc
+clear
+disp("Example 8.31a")
+printf("\n")
+disp("perform the following binary substraction using 1s complement")
+disp("a)1010-0111 b)0110-1101")
+a=[1 0 1 0]
+b=~[0 1 1 1]
+d=0
+for i=1:length(a)
+ c(i)=a(length(a)+1-i)+b(length(a)+1-i)+d
+ if(c(i)==1)
+ d=0
+ end
+ if[c(i)==2]
+ d=1
+ c(i)=0
+ end
+end
+f=1
+if(d==1)
+ for i=1:length(a)
+ g(i)=c(i)+f
+ if(g(i)==1)
+ f=0
+ end
+ if(g(i)==2)
+ f=1
+ g(i)=0
+ end
+
+ end
+ for i=1:length(a)
+ c(i)=g(i)
+ end
+end
+if(d==0)
+ for i=1:length(a)
+ c(i)=~c(i)
+ end
+end
+printf("result =%d%d%d%d",c(4),c(3),c(2),c(1))
+
|