From Logic To Math

In our previous lessons, we looked at how individual gates like NAND and XOR work. We also learned how to count in binary. Now, we are going to combine those two ideas.

Think of logic gates as the building blocks of a brain. On their own, they just respond to high or low voltages. But when we wire them together in specific ways, they can perform math just like a calculator. In this lesson, we will build a circuit that can add numbers together. This is the first step toward building a central processing unit (CPU).

The Rules Of Binary Addition

Before we build the circuit, we need to remember the four basic rules of adding single bits. In binary, addition looks very similar to the math you learned in school, but it is much simpler because there are only two digits: 0 and 1.

OperationResultSum (SS)Carry (CC)
0+00 + 0
The Half Adder

To turn these rules into a circuit, we need two outputs. Let's look at the Sum (SS) column in the table above. The Sum is 1 only when the inputs are different (0+10+1 or 1+01+0). This is exactly how an XOR gate behaves!

Now look at the Carry () column. The is only when both inputs are . This is the behavior of an gate.

The Full Adder

In real computers, we add long strings of numbers. When you add the second column of a math problem, you often have to include a carry from the first column.

A Full Adder handles three inputs instead of two:

  1. Input A: The first bit.
  2. Input B: The second bit.
  3. Carry In (CinC_{in}): The carry bit from the previous addition.

By adding this third input, we can chain many adders together to add very large numbers. The logic gets slightly more complex, but the goal is the same: produce one Sum output and one Carry Out () output.

Circuit Logic Breakdown

To build a Full Adder, we combine two stages of logic. Let's look at how the circuit you will work with is organized:

1. Finding the Sum (SS) The Sum is calculated by checking if the total number of 1 inputs is odd. We use two XOR gates for this.

  • The first XOR gate compares A and B.
  • The second XOR gate compares that result with CinC_{in}.
Summary And Practice

In this lesson, we moved from simple logic gates to a functional math circuit. You learned that:

  • Binary addition follows four simple rules.
  • An XOR gate is the primary tool for calculating a Sum.
  • A Full Adder uses a Carry In (CinC_{in}) to allow for multi-bit addition.

Now it is time to put this into practice. In the next section, you will go into the CodeSignal Logic simulator to wire these gates together. You will follow a provided design to create a working 1-bit Full Adder that takes three inputs and produces the correct Sum and Carry bits. Pay close attention to how the signals flow from the inputs through the and gates to reach the final outputs!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal