Sei sulla pagina 1di 6

Signed Magnitude Representation

EE260 Introduction to Digital


Design

The easier representation to understand, and the one that we


usually employ with decimal numbers
Use 1 extra symbol (the sign) to indicate whether the number is
positive or negative (+ or -)
Typically we use the convention that + is the default

With binary representation, we need one extra bit of information (1: , 0: +)

Unfortunately not so practical:

Ex. 10110 is interpreted as -6

Lecture 3: Number Systems:


Representation of Negative
Numbers

Complement Number Systems


Represent negative numbers in base r by
complementing their positive representation
Two types:
Radix complement: -x represented as rN-x
Diminished radix complement: -x represented as rN-x1

Need to know the number of bits of the


representation (N)
The complement of a complement is the starting
number (as it should be, as -(-(x))=x )

Makes operations more complicated (ex. A+B is an addition if both are


positive or negative, a subtraction if A is positive and B is negative, a
different subtraction if A is negative and B is positive)
The MSD, the sign bit has a different interpretation than all the others
The number 0 has 2 different representations (-0 and +0)

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

Example: 10s complement


representation
Consider the numbers that we can represent
with 4 digits (from 0000 to 9999)
The 0 is represented naturally (0000)
The positive numbers representable span the
interval 1 to 4999 (=(104/2)-1) (also in their
natural interpretation)
The negative numbers span the interval -5000
to -1

What is the advantage of the radix


complement representation?
Uniform operation:
If A+B still belongs to the range ((rN)/2 to (rN)/2 -1) ,
the addition can be performed with the same
operations without distinguishing the signs of the
operands. Why?
If A and B are both positive trivial
If A is positive and B is negative, with B=-X, B is represented
as rN-X, and A+B=A+ rN-X= A-X+ rN. As we discard the N+1th
digit, we obtain A-X. Correct!
Same applies with other combination of signs (check!)

The number 6789 is negative (because it is >=5000)


It is x where x is such that 6789=10000-x:
x= 10000-6789=3211

In conclusion, 6789 represents -3211

Unique representation for 0.

But how do we easily compute a


radix complement?
Two possible techniques:
1. Compute rN-x-1 and then add 1.

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. Starting from LSD:


1. If it is 0, keep it 0
2. With the first non-0 digit, r-complement it
3. (r-1)-complement all the following digits

Example 1st technique


10s complement of the 4 digit number 2370:
9-complement each digit:

2 9-2=7
3 9-3=6
7 9-7=2
0 9-0=9

The result is the 9s complement: 7629


Add 1: 7630
Check: 10000-2370=7630

Why does it work?


rN-1, represented as an N-bit positive
number, is (qqqq)r (q=r-1)
Example, if r=10 N=4, 10000-1=9999

rN-1-x, therefore, is (qqqq)r x


Performing the subtraction, no borrow is
possible (all digits are at most =q)
So each digit of the result is q subtracted
by the corresponding digit of x

Why does it work?


Equivalent to executing a regular
subtraction 100.0 x and dealing with
borrow:
LSdigits=0 give 0 and no borrow
First non-0 digit d gives 10-d and borrow
All successive digits give 10-d-borrow=9-d
MSD=1-borrow=0.

Example 2nd technique


10s complement of the 4 digit number
2370:
Starting from LSD towards MSD:
00
7: first non-0 digit 10-7=3
3: no longer first non-0 digit 9-3=6
2 9-2=7

Result: 7630

What happens with binary?


Rs complement is 2s complement
With a N-digit number we represent
the positive numbers between 1 and 2N-1-1
the negative numbers between (2N-1) and -1

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!

Given a positive binary number x, its 2s complement


can be calculated one of the two techniques described
for generic r:
1s complement bit by bit (1 0, 0 1), and sum 1 to the
result, or
Starting from LSB, keep all the digits until the first 1, then
complement the remaining bits

Examples in binary

Diminished radix complement

Find the 2s complement of the binary number


01110100:

Same as radix complement, but use rN-1-x instead of rNx


It represents all numbers between ((rN)/2-1) to (rN)/2 -1)
balanced representation
Advantage: easier to calculate (complement every digit)
Disadvantages:

1st method: 10001011+1=10001100


2nd method: from LSB to MSB

00
00
1 1 (first non-0)
01
10
10
10
01

2 representations for 0 (000..00 and qqq..qq, where q=r-1)


Adder design a little bit trickier

Normally just used as a help in conversion to 2s


complement

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

How to identify overflow?


It is important to have a way of checking if
overflow occurred.
It might only happen if 2 numbers of the
same sign are added
Detection:
Addends have the same sign, but result has a
different one

Alternative method: look at the carries for


the MSB and its carry

Overflow detection example (1)


1000
1011+
1100=
-----------10111
discarded

Negative operands

-5+
-4=
---+7?????

Overflow detection example


1000
1011+
1100=
-----------10111

-5+
-4=
---+7?????

discarded

Overflow detection example (2)


1000
1011+
1100=
-----------10111

MSB Carry out


=
MSB Carry in

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:

2s complement and unsigned


arithmetic circuits
Exact same structure
Different interpretation

A-B=A+B+1
Easy to do with almost the same circuit of
addition!
Same concept for overflow as well

Potrebbero piacerti anche