**Points of Discussions **

**Definition and Overview of Binary Subtractor****Half Subtractor****Full Subtractor****N -bit Subtractor****Applications of binary subtractor****VHDL implementation of half subtractor and full subtractor**

**Definition and Overview**

A subtractor is a device that subtracts two numbers and produces the result. A digital or binary subtractor is something that deals with the Subtraction of binary digits.

A binary subtractor is needed for digital computation inside a digital device or a digital computer. The most convenient way of Subtraction unsigned binary numbers is the method of complements. There are rules for binary Subtraction.

The binary subtraction rules are stated as follows. Here 0 is logic low, and one is logic high. A and B are two inputs.

A | B | Y = A – B |

0 | 0 | 0 |

0 | 1 | 1 (borrow 1) |

1 | 0 | 1 |

1 | 1 | 0 |

**Example of subtraction operations:**

1101 – 1011

1101

– 1011

= 0010

So, the answer is 0010

Methods of complements can alternatively carry out binary subtractions for binary subtractors. There are two types of complement methods that are generally used.

**A. 1’s Complement**

**B. 2’s Complement**

**Steps for performing 1’s complement:**

**Find out the 1’s complement of the number that is to be subtracted.****Now the 1’s complement is added to the number from which the Subtraction is desired.****Where there is one carry in the last position, of the result of the addition in step 2, the carrier is removed and added to the product without the carry to obtain the final result.**

**Let us take an example – 1101 – 1011**

1’s complement of 1011 = 0100

Now, add 1101 with 0100

1101

+ 0100

= 1 0001

As we can see, there is one as a carry, so we remove the carry and add the carry again with the obtained result.

0001

+ 1

= 0010

So, the answer to the Subtraction is 0010

**For 2’s complement method**

**Calculate the 2’s complement.****The complement is now added with another number.****The carry is rejected.**

**Let us take an example – 1101 – 1011**

2’s complement of any number is calculated by performing 1’s complement and adding 1 to it.

2’s complement of

Now, add 1101 with 0100

1101

+ 0100

= **1** 0001

As we can see, there is one as a carry, so we remove the carry and add the carry again with the obtained result.

0001

+ 1

= 0010

So, the answer to the Subtraction is 0010

Digital computers use the 2’s complement method for calculations as it requires less carry.

The complement methods in the decimal number system are known as 9’s and 10’s complement method.

Various digital circuitries implement this subtraction operation. They are –

**Half Subtractor****Full Subtractor**

A binary subtractor not only performs addition operations but also used in digital applications. Decoding and encoding of values, calculation of the index is a few of its applications.

**Half subtractor**

A half binary subtractor is a binary subtractor that subtracts one bit of data and produces the result. It has two input sides through which we supply the digital logic values, and it has two outputs through which we receive the impact of the operation. The result can be shown in a single digit. The work shows the number in the Subtraction that has the same significance as the individual digits subtracted. The other output shows the borrow bit.

**The half subtractor truth table**

The working of the half binary subtractor is shown in the following truth table.

A | B | Difference | Borrow |

0 | 0 | 0 | 0 |

0 | 1 | 1 | 1 |

1 | 0 | 1 | 0 |

1 | 1 | 0 | 0 |

**Half Subtractor circuit**

From the truth table, we can conclude that the first three rows can represent the result using a single digit. In the second row, the work is described using two numbers as it has borrowed as 1.

Difference = A′B + AB′

Borrow = A′B

So,

Difference = A XOR B

Borrow = A′ AND B

We need one XOR gate, one NOT gate, and one AND gate to implement the logic. XOR gate, NOT gate, an AND gate can also be made using universal gates like NAND and NOR. So, a half subtractor can be designed using only universal gates.

The following image shows A and B as the input and D as the difference, and C as they borrow.

**Full Subtractor**

Full Binary Subtractor is another kind of binary Subtractor which provides the result of a binary subtraction operation. When two binary numbers are subtracted, except for the least significant digit, there is a borrow-in as B_{i-1 }and borrow out as B_{i}. The full Subtractor is designed to handle a borrow-in for each stage. That is how an entire order overcomes the shortcoming of half Subtractor of running borrow-in.

A full subtractor truth table

X_{i} | Y_{i} | B_{i-1} | D_{i} | B_{i} |

0 | 0 | 0 | 0 | 0 |

0 | 0 | 1 | 1 | 1 |

0 | 1 | 0 | 1 | 1 |

0 | 1 | 1 | 0 | 1 |

1 | 0 | 0 | 1 | 0 |

1 | 0 | 1 | 0 | 0 |

1 | 1 | 0 | 0 | 0 |

1 | 1 | 1 | 1 | 1 |

**Full subtractor circuit**

**Difference = A′ B′ B _{in} + A B′ B_{in}′ + A′ B B_{in}′ + A B B_{in} **

**Borrow = A′ B _{in} + A′ B + B B_{in} **

To implement the expression using logical gates, we need to simplify the word further.

Difference = A′ B′ B_{in} + A B′ B_{in}′ + A′ B B_{in}′ + A B B_{in}

Or, Difference = B_{in} (A′B′ + AB) + B_{in} ′ (AB′ + A′B)

Or, Difference = B_{in} (A XNOR B) + B_{in} ′ (A XOR B)

Or, Difference = B_{in} (A XOR B) ′ + B_{in} ′ (A XOR B)

Or, Difference = B_{in} XOR (A XOR B)

Or, Difference = (A XOR B) XOR Bin

Borrow = A′ B′ B_{in} + A B′ B_{in}′ + A′ B B_{in}′ + A B B_{in}

Or, Borrow = A′ B′ B_{in} +A′ B B_{in} ′ + A′ B B_{in} + A′ B B_{in} + A′ B B_{in} + A B Bin

Or, Borrow = A′ B_{in} (B + B′) + A′B (B_{in} + B_{in} ′) + B B_{in} (A + A′)

Or, Borrow = A′ B_{in} + A′B + B B_{in}

The expression can be written in another way –

Bout = A′ B′ Bin + A′ B Bin′ + A′ B Bin + A B Bin

Or, Borrow = Bin (AB + A′ B′) + A′ B (Bin + Bin′)

Or, Borrow = Bin (A XNOR B) + A′ B

Or, Borrow = Bin (A XOR B) ′ + A′ B

As the circuit diagram shows, A, B, and B_{in. }The circuit gives two output as difference output and borrows output. The B_{in }is set to 1 whenever there is borrow in input A. B_{in }is then subtracted from A and Y.

The general expression can be written as D = A – B – B_{in} + 2 B_{out.}

Full subtractors can also be implemented using half subtractors.

**N bit Subtractor**

In a single bit binary subtractor, Subtraction of only 1 bit can be performed. If we need to perform Subtraction of n -bit, then a n bit binary subtractor is required. An n-bit subtractor can be implemented similarly using subtractors in a cascaded form.

**Applications of Subtractors**

- Subtractors are often used with adders. Whenever an adder is needed for a circuit, a subtractor is also required.
- ALU, which is responsible for the calculation, and stays inside a microprocessor, also needs subtractors. CPUs also need subtractors for operation.
- Microcontrollers also use subtractors for performing the digital computation.
- Subtractors are also used in Digital Signal Processing Domain.
- Digital computers use a lot of subtractors.

*How an Adder works? Truth Tables and Circuit Diagrams! Click to know!*

**VHDL Implementation of Half Subtractors & Full Subtractors**

**Half Subtractor Dataflow Modelling**

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity ENTITY_NAME is

Port ( A : in STD_LOGIC;

B : in STD_LOGIC;

IB : in STD_LOGIC;

Diff : out STD_LOGIC;

Borr : out STD_LOGIC);

end ENTITY_NAME;

**Architecture Dataflow**

architecture Dataflow of ENTITY_NAME is

begin

Diff <= (A xor B) xor IB;

Borr <= ((not A) and (B or IB)) or (B and IB);

end dataflow;

**Full Subtractor Dataflow Modelling**

entity ENTITY_NAME is

Port ( A : in STD_LOGIC;

B : in STD_LOGIC;

IB : in STD_LOGIC;

Borr : out STD_LOGIC;

Diff : out STD_LOGIC);

end ENTITY_NAME;

**Architecture dataflow**

architecture Behavioral of ENTITY_NAME is

begin

process(A,B,IB)

begin

if(A=’0′ and B=’0′ and IB=’0′ )then

Diff<=’0′;

Borr<=’0′;

elsif(A=’0′ and B=’0′ and IB=’1′ )then

Borr<=’1′;

Diff<=’1′;

elsif(A=’0′ and B=’1′ and IB=’0′ )then

Borr<=’1′;

Diff<=’1′;

elsif(A=’0′ and B=’1′ and IB=’1′ )then

Borr<=’0′;

Diff<=’1′;

elsif(A=’1′ and B=’0′ and IB=’0′ )then

Borr<=’1′;

Diff<=’0′;

elsif(A=’1′ and B=’0′ and IB=’1′ )then

Borr<=’0′;

Diff<=’0′;

elsif(A=’1′ and B=’1′ and IB=’0′ )then

Borr<=’0′;

Diff<=’0′;

else

Borr<=’1′;

Diff<=’1′;

end if;

end process;

end Behavioral;

**For more electronics related article click here**

- Op Amp | How does an Op – Amp Work? | 7+ Important parameters of Op Amp
- Magnetron Microwave | Construction and Applications | It’s 4+ Important Phases
- Time Domain Reflectometer | Description and Overview | 5+ Important Applications
- Klystron | Working and Important Applications| Analysis of 5+ Types
- SWR Meter | Working and Overview | 7+ Important Steps Explanation
- Rectangular Waveguide | 3+ Important Modes| Characteristic Table
- Microwave Resonators | Analysis of 3+ Important types | Circuits and Equations
- Transmission lines and Waveguides | Analysis of 3+ Types | Important Equations
- Microwave engineering | 7+ Important Applications | All You Need To Know
- Circuit Theory | 10+ Important Mathematical Problems
- Star Delta Connection | Complete Overview | It’s 5+ Important Relations
- Millman’s Theorem | Overview and Explanations | 3+ Important Steps