summaryrefslogtreecommitdiff
path: root/273/CH25/EX25.28
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /273/CH25/EX25.28
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '273/CH25/EX25.28')
-rwxr-xr-x273/CH25/EX25.28/ex25_28sce.sce35
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