You are on page 1of 4

COE/EE 243 Lecture #3

Homework #1 passed out (see link on web page if you don't have a copy)
Binary Arithmatic--continued

However, it is more common to add a positive number to a negative
number than to perform straight subtraction.
** Representation of Negative Numbers
Most computers use 1st bit of a word that represents an integer
as a sign bit. 0 means positive, 1 means negative.
We will discuss 3 ways to represent integers - all 3 use a sign bit.
* Signed-Magnitude Representation
For an n-bit word, the first bit is a sign bit and
the remaining n-1 bits are the magnitude.
There are an equal number of positive and negative numbers
and there are two representations for zero.
+3 = 00011 -2 = 10010 0 = 00000 = 10000
This does not gain much for subtraction.
* Complement Number Systems
-- Radix Complement Representation
The radix complement of an n-bit number is obtained by
n
subtracting the number from R .
Decimal number examples:
4-bit complement (10's complement) of 2,067 = 10,000 - 2,067 = 7,933
4-bit complement (10's complement) of 0 = 10,000 - 0 = 0 (not 10000)
Since we can't do 10000 with 4 bits, only 9999 need to modify our
approach a little for implementing this.
Can write as (9,999 + 1) - 2,067 = (9,999 - 2,067) + 1
= (complement of 2,067) + 1
-- Two's Complement Representation
Most significant bit (MSB) is sign bit. A number is negative if MSB is 1.
Since the sign bit changes when we take the complement, the complement
of a positive number is a negative number.
+17 = 00010001
-17 = 11101110 + 1 = 11101111 (two's complement of 17)
0 = 00000000 (only one representation for zero)

+1 = 00000001
-1 = 11111110 + 1 = 11111111

+127 = 01111111
-128 = 01111111 + 1 = 10000000
An easier way to find 2's complement is to start at right
and complement everything left of the first '1'
-- Diminished Radix Complement Representation
In this system, the complement of an n-bit number is obtained by
n
subtracting the number from (R - 1).
Decimal number examples:
4-bit complement (9's complement) of 2,067 = 9,999 - 2,067 = 7,932
4-bit complement (9's complement) of 0 = 9,999 - 0 = 9,999
-- One's Complement Representation
MSB is sign bit. A number is negative if MSB is 1.
+17 = 00010001
-17 = 11101110
0 = 00000000
0 = 11111111

+1 = 00000001
-1 = 11111110
Complement every bit
Two's One's Signed
Decimal Complement Complement Magnitude
------- ---------- ---------- ---------
7 0111 0111 0111
6 0110 0110 0110

2 0010 0010 0010
1 0001 0001 0001
0 0000 0000 0000
-0 -- 1111 1000
-1 1111 1110 1001
-2 1110 1101 1010
-7 1001 1000 1111
-8 1000 -- --
Note that none of these can do +8
** Two's-Complement Addition and Subtraction
When adding 2's-complement numbers ignore the carry out.
Overflow occurs when the sign of the numbers to be added
are the same, but the result is of the opposite sign.
+3 0011 +5 0101 +5 0101
+4 0100 +6 0110 -6 1010
-------- -------- --------
+7 0111 +11 1011 -1 1111
(overflow)
-5 1011 -3 1101 -5 1011
+6 0110 -4 1100 -6 1010
-------- -------- --------
+1 0001 -7 1001 -11 0101
Ignore (overflow)
carry out
Subtraction generally performed by complementing subtrahend
and adding with a carry in (to get the 2's complement).
Key points: 1) Add the sign bit
2) Discard the final carry
3) If sign bits of both numbers are the same, and the
sign of the result is different, overflow.
** One's-Complement Addition and Subtraction
When adding 1's-complement numbers, add the carry out
to the partial sum to get the final result (end-around carry).
Partial Proof:
-A + B (assume B > A)
n n
= (2 - 1 - A) + B = 2 + (B - A) - 1
n
an end-around carry same as subtracting 2 and adding 1.
Overflow same as for 2's-complement case.
-5 1010 -3 1100 -5 1010
+6 0110 -4 1011 -6 1001
-------- -------- --------
0000 0111 -11 0011
1 1 1
---- ---- ----
+1 0001 -7 1000 0100
(overflow)
Subtraction generally performed by complementing subtrahend
and adding.

You might also like