summaryrefslogtreecommitdiff
path: root/1241/CH2/EX2.36/exa2_36.sce
blob: 62ab4f0aa70935f0aa3c999573e8b8b2fcb349e9 (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
//Example 2-36//
//-17 in two's complement by third method//
clc
//clears the console//
clear
//clears all existing variables//
a=00010001
c=0
z=0
for i=1: 8
    x(i)=modulo(a,10)
    a=a/10
    a=floor(a)
end    
for i=1: 8
    if c>1 then
       break 
    end
    if x(i)==1 then
        for k=i+1: 8
        x(k)=bitcmp(x(k),1)
        c=c+1 
        end
    end
end
for i=1: 8
    z=z+x(i)*10^(i-1)
end
disp('-17 in twos complement is :') 
disp(z)      
//answer is displayed//