Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Radix complement
Represent x by rN-x, but keeping the N least significant
bits only
If x is between 1 and rN-1, -x is represented by a number
in the same range
If x=0, rN-x is rN=(1000)r (in N+1 digits), so that its
complement is still =0 (discard the N+1 digit) only one
representation for 0
How do we distinguish a positive from a negative
number?
With a N-digit number we represent
the positive numbers between 1 and (rN)/2-1
the negative numbers between (rN)/2 and -1
Then, all the negative numbers will have the MSD>=r/2, all the
positive numbers will have the MSD<r/2
rN-x-1 is easy to compute, as it is sufficient to (r-1)complement each digit separately (for example, if
r=10, just substitute each digit d with 9-d)
2 9-2=7
3 9-3=6
7 9-7=2
0 9-0=9
Result: 7630
Then, all the negative numbers will have the MSD=1, all the
positive numbers will have the MSD=0: As in sign-magnitude!
Easy to see!
Examples in binary
00
00
1 1 (first non-0)
01
10
10
10
01
Result=10001100
Addition in 2s complement
Overflow
000
As mentioned,
addition is uniform
for all combination
of signs
110
Key point: x+1
applies uniformly
to all numbers
Equivalent to a
clockwise move
on a circle
111
000
001
0
-1
+1
-2
-3
101
3
-4
100
011
010
When, in
adding a
number, we
cross the limit
for the
representation,
we have
overflow
111
001
0
-1
+1
110 -2
-3
101
010
3
-4
011
100
Negative operands
-5+
-4=
---+7?????
-5+
-4=
---+7?????
discarded
OVERFLOW!
-5+
-4=
---+7?????
Positive result
OVERFLOW!
Subtraction?
In 2s complement subtraction A-B can be
performed as addition of A with Bs 2s
complement
In practice, the second operand needs to
be complemented bit by bit and 1 added:
A-B=A+B+1
Easy to do with almost the same circuit of
addition!
Same concept for overflow as well