where the "c" in the top row correspond to the carry (with a value of 1). Notice that the addition was performed on consecutive place values, from the least significant digit to the most significant digit. In the 1's place, the sum of the digits is 18; since this is greater than 9, 8 is written down in the 1's place and the 1 is carried to the place value on the left (10's). The carry is then added into the next place value.

c 2 9 + 1 9 - - 4 8

By analogy, in an arbitrary base "n", if the sum of the digits in any place value is greater than n - 1, the 1's portion of the sum is written down and the "n's" portion is carried to the place value on the left. In the binary number system, therefore, if the sum of the digits in any place value is greater than 1, the 1's portion of the sum is written down and the 2's portion is carried to the place value on the left:

In this example,

c c c c c 1 1 1 0 1 + 1 0 0 1 1 - - - - - - 1 1 0 0 0 0

You should verify that this binary example corresponds to the previous example in decimal.

- 1 + 1 in the 1's place was 10
_{2}: the 0 was written down in the 1's place and the 1 was carried into the 2's place.- 1 + 0 + 1 in the 2's place was 10
_{2}, and the 0 was written down in the 2's place and the 1 was carried into the 4's place.- In the 4's place, 1 + 1 + 0 was 10
_{2}, with 0 written in the 4's place and 1 carried into the 8's place.- The same thing happened in the 8's place.
- In the 16's place, 1 + 1 + 1 was 11
_{2}, with the 1 written in the 16's place and 1 carried into the 32's place.- And in the 32's place, 1 + 0 + 0 was 1.

In exactly the same fashion, we can do hexadecimal addition:

In this example, D

c 1 D + 1 3 - - 3 0

Suppose that we wish to subtract 1 1 0 1_{2} from 1 1 0 1 1_{2} :

The first step is to compute the "

1 1 0 1 1 - 1 1 0 1 - - - - - ?

0 0 1 1 0 1Notice that before taking the complement, we inserted leading zeroes: this is necessary whenever we are subtracting a number which has fewer bits than the number of bits in our adder (enough leading zeros must added so that the two numbers have exactly that number of bits)._{2}becomes 1 1 0 0 1 0_{2}.

The 2's complement is then obtained by simply adding 1 to the 1's complement:

To perform the subtraction, we just add the 2's complement to the number which we originally wanted to subtract from:

1 1 0 0 1 0 + 1 - - - - - - 1 1 0 0 1 1 Notice that the left most bit is 1; this tells you that the value is negative.

Notice that we have a carry left over; when using 2's complement subtraction, this is expected: the final carry is "thrown away."

c c c c 0 1 1 0 1 1 + 1 1 0 0 1 1 - - - - - - 0 0 1 1 1 0

It is not actually thrown away; it is ignoredIt is amusing to note that this technique works in any number system: if you don't like to borrow in ordinary decimal subtraction, you can always add the "10's complement" instead. For example, 27 - 13 can be computed by first finding the "9's complement" of 13, which isbecause we put it there in the first place, by taking the 2's complement. Note that taking the 1's complement is the same as subtracting from all 1's; for a 6 bit adder,0 0 1 1 0 1is the same as_{2}→ 1 1 0 0 1 0_{2}1 1 1 1 1 1When we took the 1's complement and then added 1, it was like adding the_{2}- 0 0 1 1 0 1_{2}.7 bit value1 0 0 0 0 0 0to - 0 0 1 1 0 1_{2}_{2}. That seventh bit became the final carry that we ignored.

99 - 13 = 86,adding 1 to get the "10's complement" and adding that to 27:

We then throw away the extra carry to get 14.

c c 2 7 + 8 7 - - 1 4

add 1 to that to get F3

F F - 0 D - - F 2

But borrowing is not the same problem in hexadecimal as it is in the binary number system: in the previous example, we can borrow a 1 from the 16's place:

c 1 B + F 3 - - 0 E

becomes

1 B - 0 D - - ?

since 10

(10 _{16})0 B - 0 D - - 0 E

And of course by now you have realized that all of the subtraction examples above are really the same problem!

Now we are ready to see how unsigned and signed integers are stored in computers.

Go to: Title Page Table of Contents Index

©2013, Kenneth R. Koehler. All Rights Reserved. This document may be freely reproduced provided that this copyright notice is included.

Please send comments or suggestions to the author.