summaryrefslogtreecommitdiff
path: root/273/CH25/EX25.28/ex25_28sce.sce
blob: 21afe816f5b32f53c0580828f1fdcec8821919a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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');