DEV Community

Garik Paramazyan
Garik Paramazyan

Posted on

Logic gates: Half Adder, Full Adder, Half subtractor, Full subtractor.

Logic gates are building blocks of a digital circuit at the heart of any computer operation. They perform logical operations that take binary inputs and return binary output. They are used in electronic devices from mobile telephones to computers, memory devices to tablets, etc. Sometimes computers need ten, thousand, or even a million logical performances to perform complicated tasks and operations. They help computers and other devices to compute data and control data flow. There are seven logic gates AND, OR, XOR, NAND(opposite of AND), NOR(opposite of OR), NXOR(opposite of XOR), and NOT. Each of them has its logical operations with binary numbers. For example:
OR
Inputs
1.0 0 0
2.1 0 1 Output
3.0 1 1
4.1 1 1

XOR
Inputs

  1. 0 0 0
  2. 0 1 1 Output
  3. 1 0 1
  4. 1 1 0

AND
Inputs

  1. 0 0 0
  2. 0 1 0 Output
  3. 1 0 0
  4. 1 1 1

For mathematical operations like addition and subtraction existing constant logical operations for doing them. Four of them are Half Adder, Full Adder, Half Subtractor, and Full Subtractor. Half Adder takes two inputs first number, second number, and returns sum, carry. But this works only for 1-digit binary numbers(0 and 1). It consists of only XOR and AND logic gates. The first one gives the answer and the second one carry. For adding big numbers we have to use Full Adder operation. It takes three inputs first number(a), second number(b), and carry from the previous addition(carry in), and two outputs sum and carry out. Full adder consists of Half Adder plus AND, XOR, and OR. Half Subtractor is similar to Half Adder only outputs are differences of numbers, and borrow out. This also is used for 1-digit numbers. Full Subtractor takes three inputs first number(a), second number(b), borrow in, and returns difference and borrow out. By using Full Adder and Full Subtractor we can add and subtract any binary number we want.

Half Adder
Inputs Outputs

0 1-sum

1 0-carry

Full Adder
Inputs Outputs

11 110-sum

11 11-carry out
10-carry in

Half Subtractor
Inputs Outputs
0 1-difference
1 1-borrow

  1. Full Subtractor Inputs Outputs 1010 100-difference 110 100-borrow out 000-borrow in

Top comments (0)