Home  www.playhookey.com  Tue, 09192017 

Direct Current

Alternating Current

Semiconductors

Digital

Logic Families

Digital Experiments

Computers

 Analog  Analog Experiments  Oscillators  Optics  HTML Test  

 Combinational Logic  Sequential Logic  Alternate FlipFlop Circuits  Counters  Registers  The 555 Timer   

Basic Gates

Derived Gates

The XOR Function

Boolean Algebra

Binary Addition

Negative Numbers and Binary Subtraction

 TwoInput Multiplexer  FourInput Multiplexer  OnetoTwo Line Decoder/Demultiplexer  TwotoFour Line Decoder/Demultiplexer  
Adding Binary Numbers 

A key requirement of digital computers is the ability to use logical functions to perform arithmetic operations. The basis of this is addition; if we can add two binary numbers, we can just as easily subtract them, or get a little fancier and perform multiplication and division. How, then, do we add two binary numbers?
Let's start by adding two binary bits. Since each bit has only two possible values, 0 or 1, there are only four possible combinations of inputs. These four possibilities, and the resulting sums, are:
0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10
Whoops! That fourth line indicates that we have to account for two output bits when we add two input bits: the sum and a possible carry. Let's set this up as a truth table with two inputs and two outputs, and see where we can go from there.
INPUTS  OUTPUTS 
Well, this looks familiar, doesn't it? The Carry output is a simple AND function, and the Sum is an ExclusiveOR. Thus, we can use two gates to add these two bits together. The resulting circuit is shown below. 


A  B  CARRY  SUM  
0  0  0  0  
0  1  0  1  
1  0  0  1  
1  1  1  0 
To construct a full adder circuit, we'll need three inputs and two outputs. Since we'll have both an input carry and an output carry, we'll designate them as C_{IN} and C_{OUT}. At the same time, we'll use S to designate the final Sum output. The resulting truth table is shown to the right. Hmmm. This is looking a bit messy. It looks as if C_{OUT} may be either an AND or an OR function, depending on the value of A, and S is either an XOR or an XNOR, again depending on the value of A. Looking a little more closely, however, we can note that the S output is actually an XOR between the A input and the halfadder SUM output with B and C_{IN} inputs. Also, the output carry will be true if any two or all three inputs are logic 1. What this suggests is also intuitively logical: we can use two halfadder circuits. The first will add A and B to produce a partial Sum, while the second will add C_{IN} to that Sum to produce the final S output. If either halfadder produces a carry, there will be an output carry. Thus, C_{OUT} will be an OR function of the halfadder Carry outputs. The resulting full adder circuit is shown below. 
INPUTS  OUTPUTS  

A  B  C_{IN}  C_{OUT}  S  
0  0  0  0  0  
0  0  1  0  1  
0  1  0  0  1  
0  1  1  1  0  
1  0  0  0  1  
1  0  1  1  0  
1  1  0  1  0  
1  1  1  1  1 


The circuit above is really too complicated to be used in larger logic diagrams, so a separate symbol, shown to the right, is used to represent a onebit full adder. In fact, it is common practice in logic diagrams to represent any complex function as a "black box" with input and output signals designated. It is, after all, the logical function that is important, not the exact method of performing that function.
Now we can add two binary bits together, accounting for a possible carry from the next lower order of magnitude, and sending a carry to the next higher order of magnitude. To perform multibit addition the way a computer would, a full adder must be allocated for each bit to be added simultaneously. Thus, to add two 4bit numbers to produce a 4bit sum (with a possible carry), you would need four full adders with carry lines cascaded, as shown to the right. For two 8bit numbers, you would need eight full adders, which can be formed by cascading two of these 4bit blocks. By extension, two binary numbers of any size may be added in this manner.
It is also quite possible to use this circuit for binary subtraction. If a negative number is applied to the B inputs, the resulting sum will actually be the difference between the two numbers. We'll look at this subject in more detail in the page on Negative Numbers and Binary Subtraction.
In a modern computer, the adder circuitry will include the means of negating one of the input numbers directly, so the circuit can perform either addition or subtraction on demand. Other functions are commonly included in modern implementations of the adder circuit, especially in modern microprocessors.


 
All pages on www.playhookey.com copyright © 1996, 20002015 by
Ken Bigelow Please address queries and suggestions to: webmaster@playhookey.com 