diff options
Diffstat (limited to '273/CH25/EX25.28')
-rwxr-xr-x | 273/CH25/EX25.28/ex25_28sce.sce | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/273/CH25/EX25.28/ex25_28sce.sce b/273/CH25/EX25.28/ex25_28sce.sce new file mode 100755 index 000000000..21afe816f --- /dev/null +++ b/273/CH25/EX25.28/ex25_28sce.sce @@ -0,0 +1,35 @@ +clc;
+clear;
+//example25.28
+//finiding two's complement
+//a=input(" Enter the number (binary) :");
+a=1010;
+for i=1:4
+ a1(i)=modulo(a,10);
+ a=a/10;
+ a=round(a);
+
+end
+for i=1:4//making one's complement of number
+ a1(i)=bitcmp(a1(i),1);
+end
+for i=1:4
+car(1)=1;
+re(i)=a1(i)+car(i);//addition of one to one's complement to contain two's complement
+ if re(i)== 2 then
+ car(i+1)= 1;
+ re(i)=0;
+ elseif re(i)==3 then
+ car(i+1)= 1;
+ re(i)=1;
+ else
+ car(i+1)=0;
+ end;
+end;
+
+ re2=0;
+format('v',18);
+ for i=1:4
+ re2=re2+(re(i)*(10^(i-1)))
+ end;
+disp(re2,'two s complement is');
\ No newline at end of file |