DEV Community

Izabel Arabyan
Izabel Arabyan

Posted on

Logic Gates: Full Adders and Subtractors

Logic gates are fundamental building blocks in digital electronics, computing, and modern technology, responsible for performing basic logical functions on binary inputs (0s and 1s). George Boole (1815–1864) made the most significant contribution by formalizing Boolean algebra in the mid-19th century. Boolean algebra uses variables that have two possible values: true (1) or false (0). This binary logic system became the backbone of modern digital circuits. In the 1960s, Jack Kilby and Robert Noyce independently invented the integrated circuit, allowing multiple logic gates to be placed on a single chip. This paved the way for the development of increasingly complex digital systems like microprocessors.

So what is inside a logic gate?

Transistors.
Modern logic gates are composed of transistors, which act as tiny switches that can be turned on or off to represent binary values (0 or 1). Each logic gate performs a specific function by arranging transistors in particular ways.
NPN or PNP transistors (for Bipolar Junction Transistors, BJT) or MOSFETs (Metal-Oxide-Semiconductor Field-Effect Transistors) are commonly used in logic gate circuits.

Image description

How the logic gates work?

Logic gates manipulate binary signals using transistors. For instance:
In an AND gate, two transistors might be connected in series. Current will only flow (representing a 1 output) if both transistors are switched on (both inputs are 1).
In an OR gate, transistors may be connected in parallel, allowing current to flow if either transistor is switched on (either input is 1).

Image description

Here are the types and symbols of logic gates.

Image description

Now let us go over circuits that are built for doing operations.

Addition is the most basic of arithmetic operations, so if we want to build a computer, we must first know how to build something that adds two numbers together. When you come right down to it, addition is just about the only thing that computers do.

The sum of two binary numbers is given by the output of an XOR gate, and the carry bit is given by the output of an AND gate. So we can combine an AND gate and an XOR gate to add two binary digits called A and B: And we will get Half Adder.

Image description

This box is labeled Half Adder for a reason. Certainly it adds two binary digits and gives you a sum
bit and a carry bit. But the vast majority of binary numbers are longer than 1 bit. What the Half Adder
fails to do is add a possible carry bit from a previous addition.
To add three binary numbers, we need two Half Adders and an OR gate, wired this way

Image description

Begin with the A and B inputs to the first Half Adder at the left. The output is a sum and a carry. That sum must be added to the carry from the previous column, so they're inputs to
the second Half Adder. The sum from the second Half Adder is the final sum. The two Carry Outs from the Half Adders are inputs to an OR gate. You might think another Half Adder is called for here, and that would certainly work. But if you go through all the possibilities, you'll find that the Carry Outs from the two Half Adders are never both equal to 1. The OR gate is sufficient for adding them because the OR gate is the same as the XOR gate if the inputs are never both 1. Full Adder does the addition for 1-bit numbers. So, basically we need 4 Full Adders for 4-bit addition.

Half Subtractor
A half subtractor is a digital logic circuit that performs binary subtraction of two single-bit binary numbers. It has two inputs, A and B, and two outputs, DIFFERENCE and BORROW. The DIFFERENCE output is the difference between the two input bits, while the BORROW output indicates whether borrowing was necessary during the subtraction.

The half subtractor can be implemented using basic gates such as XOR and NOT gates. The DIFFERENCE output is the XOR of the two inputs A and B, while the BORROW output is the NOT of input A and the AND of inputs A and B.

Image description

Full Subtractor
First, we need to convert the binary numbers to their two’s complement form if we are subtracting a negative number. Next, we compare the bits in the minuend and subtrahend at the corresponding positions. If the subtrahend bit is greater than or equal to the minuend bit, we need to borrow from the previous stage (if there is one) to subtract the subtrahend bit from the minuend bit. We subtract the two bits along with the borrow-in to get the difference bit. If the minuend bit is greater than or equal to the subtrahend bit along with the borrow-in, then the difference bit is 1, otherwise it is 0. We then calculate the borrow-out bit by comparing the minuend and subtrahend bits. If the minuend bit is less than the subtrahend bit along with the borrow-in, then we need to borrow for the next stage, so the borrow-out bit is 1, otherwise it is 0.

Image description

Understanding logic gates is essential because it allows you to grasp the inner workings of all digital systems, from computers and smartphones to embedded controllers and complex automated systems. Whether you're an engineer, programmer, or technologist, this knowledge forms the foundation for creating, and optimizing modern technology.

Top comments (0)