Homework 2: Circuits

For this homework, we will be practicing designing and drawing circuits.

To design the circuits for this homework, you may only use the gates below; i.e, the logic gates that we have discussed in class so far. While Digital provides access to additional components, you may only use the following to get credit on this homework.

  • AND gate
  • OR gate
  • XOR gate
  • NOT gate

Note: For this homework, you should not need to use the NAND or NOR gates, but you are welcome to use them.

When using Digital, you will also need IO (Input and Output) and may need to add either a “Ground” or “Supply voltage”, found under the “Components” -> “Wires” menu. The “Ground” always outputs a 0 and the “Supply voltage” always outputs a 1; these may be helpful if you need a constant value as input to your circuit.

Circuits to Draw by Hand

For the following circuit, you should sketch out the circuit by hand (without using Digital or another tool). Why? Because we may ask you to do this on the exam! Please clearly label your inputs and outputs and ensure your drawing fits on one page. Scan or save it as a PDF (or take a picture) and upload it with your Digital files. Your name and computing ID should be clearly written along with your circuit in file you upload.

  1. Conditional Arithmetic and Logic Given three 1-bit inputs x, y, and s, design a circuit that computes the output z as follows:

    z = s ? ((x << 1) ^ y) : (x + y)

    That is:

    • If s = 0, the circuit outputs x + y
    • If s = 1, the circuit outputs (x << 1) ^ y

    Note:

    • The inputs x, y, and s are all 1-bit values.
    • Use as many output bits as needed to avoid overflow.
    • The circuit should be purely combinational.

    Think carefully about how shifting affects bit width and how conditional behavior can be implemented using basic logic components.

Circuits to Build in Digital

Design the following circuits in Digital, which you set up in Lab 4. Download the linked starter file for each circuit, which contains the required inputs with correct names as well as a built-in test suite. Save each file individually with the same filename that you downloaded and upload all of them to Gradescope.

  1. Bitcount Given a 5-bit input x, produce a 3-bit output y such that y is the number of bits in x that are equal to 1.

    That is, y should be the binary representation of the count of 1s in x. For example, if x = 10111, then y = 100 (since there are four 1s in x).

    File naming requirements:

    • Required filename: bitcount.dig
    • Starter file: bitcount.dig
  2. Increment (No Overflow) Given a 4-bit unsigned input x, design a circuit that calculates a non-overflowing increment and outputs a 4-bit unsigned value. Unlike the increment circuit in class, if incrementing would overflow (i.e., if x = 1111), the circuit should keep the output at 1111 instead of wrapping around.

    For example, given x on the left, the circuit should output the value on the right:

    • 0000 → 0001
    • 0111 → 1000
    • 1110 → 1111
    • 1111 → 1111

    Hint: Think about how you can detect the overflow condition and use it to control the output.

    File naming requirements:

  3. Divide Given two 4-bit unsigned inputs \(x\) and \(y\), design a circuit that calculates \(\lfloor x/2 \rfloor + y\). The \(\lfloor \cdot \rfloor\) operation always rounds down; that is, \(\lfloor x/2 \rfloor\) would be the integer-based divide such that 16/2 is 8 and 15/2 is 7.

    Hint: think about how left and right shifts affect the value.

    File naming requirements:

    • Required filename: divide.dig
    • Starter file: divide.dig

Important

For each of the circuits created in Digital, all inputs and outputs must be specified as single-bit values named appropriately. For example, if the instructions say “a 4-bit output \(z\)”, they should be created as four 1-bit outputs Z_0, Z_1, Z_2, Z_3, where Z_0 is the low-order bit.

Additionally, the grader will be looking for specific file names, so be sure to follow the file naming convention when saving your completed files.

Collaboration

For this homework only: As is commonly done1 on math-worksheet-like assignments, you may collaborate with other students in this class. As an exception to the usual collaboration policy, you do not need to tell us about casual interactions of the “I got \(X\), what did you get?” variety. But do cite any close collaboration or major corrections; for example if the answer to the above hypothetical was “I think \(X\) is wrong, here’s why” and then you change your answer, add a note like “mst3k suggested this answer” next to your answer. However, we expect that everyone will work on the assignment to better understand circuits, so you may not directly copy another student’s answer.

This exception does not apply to sources other than other students in this course. Websites, outside tutors, generative AI, etc., are still subject to our plagiarism rules.

As always, we reserve the right to request you explain your solutions to us and may penalize you if it appears that you did not understand what you submitted as your work.

Submit

Upload your completed assignment to Gradescope by 11:59pm on Monday, Feb 9th, 2026. Please note that your filenames must match exactly the naming scheme above to be graded. It is your responsibility to verify that they have been accepted and graded on Gradescope before the deadline.

  1. It is not clear to us that this is commonly allowed per course policies, but it is commonly done


Copyright © 2025 John Hott, portions Luther Tychonievich.
Released under the CC-BY-NC-SA 4.0 license.
Creative Commons License

This site uses Just the Docs, a documentation theme for Jekyll.