Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

II. Half Adder Circuit To build a circuit that does binary addition, we will use a modular approach. First we will write a circuit that

II. Half Adder Circuit

To build a circuit that does binary addition, we will use a modular approach. First we will write a circuit that adds two bits together, and produces the Sum bit and the CarryOut bit.

Fill in the truth table for this circuit. That is, given A and B as two bits, the output in the truth table will be the Sum (the bit you get when you add A + B) and the CarryOut (the bit that is carried over to the next column).

A |B| Sum |CarryOut| For each of the outputs, write a Boolean expression to represent it.

0 |0| | |

0 |1| | |

1 |0| | |

1 |1| | |

Sum = _________________________________________ CarryOut = _________________________________________ Lets now use logicly to build the Half Adder circuit. Go to this site: http://logic.ly/demo/ 1. Start with two input values, represented by the Toggle Switches. Drag two toggle switches into the work area. 2. Click on each one, and type a label into the Export Name of the Toggle Switch Properties box. The switches should be called A and B respectively. 3. First build the circuit for the Sum using the appropriate gates based on the Boolean expression above. 4. Next build the circuit for the CarryOut using the appropriate gates. 5. Note: you should use the same Toggle Switches as inputs to both circuits. 6. Once you have both circuits built, put a Light Bulb at the end of each and label the Export Name for each of the Light Bulbs (Sum and CarryOut). 7. Test the output of your circuits to verify that they match the output in your truth table.

III. Half Adder Python Function

Now that we have the circuit built for the Half Adder, lets see if we can implement the same functionality in Python. Fill in the code for the following function and test it out.

def halfAdder(A, B):

# fill in code here to compute Sum and CarryOut

# Note that we return the int() of the values because

# we want to return 0 and 1 rather than True and False

return int(Sum), int(CarryOut)

IV. Full Adder Circuit

The Half Adder circuit only adds two bits together, but it does not take into account the fact that sometimes we have a third bit (the Carry bit) from the previous column. A Full Adder circuit is built using two Half Adder circuits. Since we will need to use the Half Adder circuit more than once to build the Full Adder circuit, it would be nice if we did not have to redraw the whole circuit more than once. Luckily, logicly has a way to do this.

1. Go back to logicly where you built the Half Adder circuit.

2. Make sure that you have labeled the Toggle Switches and Light Bulbs.

3. Use your mouse to click and drag a box around the whole circuit. All of the elements of the circuit should be highlightes.

4. Find the Integrated Circuit icon on the top tool bar. It looks like a little square lego piece. Click on it and fill in the dialog box to create the Half Adder circuit. a. The Full Name should be Half Adder b. In the Symbol Label box, type Half Adder on two lines c. Click the Create IC button.

5. Now in the bottom of the left tool bar, under the Custom area you will see your Half Adder Integrated Circuit. It looks like a little square lego piece, but it is labeled Half Adder.

We can build a Full Adder using Half Adder circuits. Lets start with a truth table: A B CarryIn Sum CarryOut 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 Here is a diagram of a Full Adder circuit using Half Adder ICs: Use logicly to build this Full Adder circuit using the Half Adder IC that you created earlier. Test your circuit by considering all of the possible values you could have (use the truth table above to check your answers). Once you are certain it is correct, create a Integrate Circuit and call it FullAdder

V. Full Adder Python Function

Implement the Full Adder functionality in Python. Fill in the code and test it out.

def fullAdder(A, B, CarryIn):

# fill in code here to compute Sum and CarryOut

return int(Sum), int(CarryOut)

VI. 4-Bit Adder Circuit

We now have a circuit that will add a column of bits in a binary number. We can use this circuit to create a more complex circuit that will add multiple bits together. Consider the following circuit diagram:

The input here is a two 4-bit binary numbers A and B. a0 is the rightmost bit of A, etc. The result is a 5-bit binary number, Sum, where sum0 is the rightmost bit of the Sum. Note how it works:

The first column (a0 + b0) is added using a Half Adder because there is no carry bit.

The Sum output from each Adder circuit becomes the sumi bit of the result

The CarryOut output from each Adder circuit becomes the CarryIn input to the next Adder circuit

Use logicly to build this circuit. You will have 8 inputs and 5 outputs. Test your results using the answers to the binary addition problems from Part I above.

VII. 4-Bit Adder Python Function

Implement the 4-Bit Adder functionality in Python. Fill in the code and test it out.

def fourBitAdder(A, B):

# A and B are strings representing binary numbers

# Note that since Python strings begin indexing from

# the left and binary numbers begin indexing from the

# right, we will have to revers the string in order to

# access the bits the way we expect

# Use the following code to reverse the strings

a = A[::-1]

b = B[::-1]

# Fill in code here to compute the result. The result

# should be a string representing the result of the binary

# addition of A and B

return result

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions