Complement Arithmetic

Home
Ch 1 and 2 Student Questions
Ch 3 and 4 Student Questions
Operating System Types
Chapter 1
Chapter 2
Chapter 3A
Chapter 3B
Chapter 4A
Chapter 4B
Labs
Section 002 Syllabus
Section 004 Syllabus
Instructions
Complement Arithmetic


Weather Closings

COMPLEMENTS TO YOU!

INTRODUCTION

Complement arithmetic is a slick way to do represent negative numbers with a finite length word. A major benefit is that it permits subtraction without having to think about borrowing from adjacent columns when you use finite length arithmetic. Computers use One's Complement or Two's Complement arithmetic internally. It is very useful for computer professionals to be able to do this in hexadecimal or octal for tracing through memory dumps to see what went wrong on a computer run. IMPORTANT: From a computer's point of view, the advantage is that subtraction can be implemented as a combination of complement and addition. No extra subtraction hardware is required.

BASE 10

We will begin with an illustration in base ten. We learned base 10 arithmetic because most humans have 10 digits (8 fingers, 2 thumbs), the original digital calculator. If we want to perform the subtraction 724 - 538, we would do the following.

After
Borrow

6

11

14

 

7

2

4

-

5

3

8

Result

1

8

6

The problem with this approach is that you must determine if you need to borrow from the column immediately to the left. If so, you add the amount borrowed from the current column and subtract it from the left-adjacent column. After completing the borrow operation, you then perform the subtraction. Humans can do this without much additional attention when we work with base 10 because we have practiced it for years. It is not quite as efficient as we would like for implementation on a computer. We can make this easier.

Suppose we are only allowed to 3-place numbers, 000 through 999. We are required to represent all positive and negative numbers we work with by using these numbers. To represent a number using complement arithmetic using base 10, do the following.

    9 9 9
Subtract   5 3 8
Intermediate
Result
  4 6 1
Add   0 0 1
Complement   4 6 2

The top line consists of a finite length word filled with our highest digit in our base 10 number system, which is 9. Recall, the digits in base 10 run from 0 through 9. The next line is our traditional negative number. If our negative number were only 2 digits, it would be treated as having leading zeros to the left. The number in the second row is subtracted from the top row. Notice that no borrows are required from adjacent columns. The third row is the result of this subtraction. In base 10, this number is the Nine's Complement.

The final operation is to add 1 to the nine's complement. This produces our Radix Complement, where the radix of the number system is 10. This is our negative number. To complete the subtraction we started with, we add this radix complement to the original number. We throw away any digits that carry beyond the third column.

Original
Number
Throw
Away
7 2 4
Radix
Complement
Add 4 6 2
Final
Result
1 1 8 6

The result is 186.

Try some examples. Using 4 digits, compute: 3928 - 489 = 3439.

Radix Complement of -489 is 9511. 3928 + 9511 = 1|3439 = 3439. The vertical bar separates the 4 digit number we keep from the fifth digit we throw away.

Try: -239 - 398 using 4 digits.

 

BASE 16 (Hexadecimal)

The principles with base 16 are the same as for base 10, except that we have 16 digits (0 through F) to use. Instead of subtracting from 9999, we subtract from FFFF.

The problem is to compute:

 

7

D

4

-

5

C

E

Result

2

0

6

Begin by finding the16's Complement of 5CE.

 

F

F

F

-

5

C

E

Result

A

3

1

 

 

Find the Radix Complement by adding 1 to the 16's Complement.

 

A

3

1

Add

   

1

Result

A

3

2

To perform the original subtraction, now do addition.

Carry

1

1

   
   

7

D

4

-

 

A

3

2

Result

1

2

0

6

 
Comments and suggestions should be sent to the Webmaster

Phone: (910) 246-9864
Curtis I. Caldwell
180 N. Bennett St. Apt. #1A
Southern Pines, NC 28387

Maverick Productions 1997 - 2000