- We can calculate the sum of two bits
- We can come up with two different values, based on the carry in
-
|
Carryin
/Bits | 0 0 | 0 1 | 1 1 |
| Cout | S |
Cout | S |
Cout | S |
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 | 0 | 1 | 1 |
- We have three things to represet here
- The two bits
- The sum if the carry in is 0/1
- The carryout
- We will represent a sum of 1 and a carryout of 0 as
- 0'1
- Or in general C'S
- So the above table becomes:
-
|
Carryin
/Bits | 0 0 | 0 1 | 1 1 |
| 0 | 0'0 | 0'1 | 1'0 |
| 1 | 0'1 | 1'0 | 1'1 |
- We wish to construct a set of conditional sums, so we will generate
an orderd pair.
- The first number represents the result if carryin = 1
- The second number represents the result if carryin = 0
- (1'0,0'1) represents adding 1 and 0 (or 0 and 1)
- These partial sums can be constructed in parallel.
- Algorithm:
1. Allign the bits of the two numbers
2. For each pair of bits, construct the partial sum (from the table above)
3. Repeat until only one pair of sums exist
4. Construct the carryin=0 sum
5. Construct the carryin = 1 sum
6. Look at carry in to determine final result.
Construct carryin = 0 sum (a'wwww, b'xxxx) and (c'yyyy ,d'zzzz)
1. Leftmost bits = zzzz (since carryin = 0)
2. If d = 0, rightmost bits = b'xxxx (output = b'xxxxzzzz)
3. If d = 1, rightmost bits = a'wwww (output = a'wwwwzzzz)
Construct carryin = 1 sum (a'wwww, b'xxxx) and (c'yyyy ,d'zzzz)
1. Leftmost bits = yyyy (since carryin = 1)
2. If c = 0, rightmost bits = b'xxxx (output = b'xxxxyyyy)
3. If c = 1, rightmost bits = a'wwww (output = a'wwwwyyyy)
- Example: Add 111001 and 110010, form the partial sums
1 1 1 0 0 1
1 1 0 0 1 0
(1'1,1'0) (1'1,1'0) (1'0,0'1) (0'1,0'0) (0'1,0'1) (1'0,0'1)
- At the next stage, we can find the result from the previous stage
-
(1'1,1'0) (1'1,1'0) (1'0,0'1) (0'1,0'0) (0'1,0'1) (1'0,0'1)
(1'11,1'10) (0'11,0'10) (0'10,0'11)
(1'11,1'10) (0'1010,0'1011)
(1'101010,1'101011)
- Since there is no carryin the sum is 101011, and the carryout = 1
- Notice, that each partial sum is independant of the others
- The time for each operation does not depend on the number of bits
in the number, so
- this is done is O(log2 n)
- A tk-gate implementation