Subtractors: Half & Full Explored - CSU1289 - Shoolini U

Substractors

1. The Puzzle of Binary Subtraction

Imagine you're navigating the vast sea of binary data, a digital sailor battling the waves of 1s and 0s. You are faced with a crucial task: you need to subtract one binary number from another. This could be a daunting task given the complexity of binary-to-decimal conversions and the potential for errors. But wait, there is a more straightforward and efficient way to achieve this: the use of subtractors in digital electronics.

Subtractors are the unsung heroes of digital systems, quietly performing binary subtraction without the need for cumbersome conversions. They are instrumental in performing arithmetic operations in computers and digital systems, providing the foundation for more complex mathematical and logical functions.

Let's set sail on this exciting journey to understand the mechanics of subtractors, focusing on half subtractors and full subtractors, and the role of the NOT gate in their operation.

2. The Half Subtractor

To unravel the mystery of subtractors, we begin with the simpler variant—the half subtractor. A half subtractor is a digital circuit that performs the subtraction of two binary digits. However, just like its counterpart, the half adder, it has a limitation—it doesn't account for any borrow from a previous subtraction.

The half subtractor is designed using the XOR gate, the AND gate, and the introduction of a new player, the NOT gate. The NOT gate, or the inverter, flips the input; if the input is 1, the output is 0, and vice versa.

2.1 Half Subtractor: Design and Function

In a half subtractor, two binary inputs, say A and B (where A is the minuend and B is the subtrahend), are subtracted to produce two outputs: the difference (D) and borrow (Bo).

The XOR gate computes the difference, just like in a half adder. The AND gate, coupled with the NOT gate, calculates the borrow. The NOT gate is connected to the first input of the AND gate, inverting A before it's input to the AND gate. This arrangement ensures that the borrow is 1 only when A is 0 and B is 1, which aligns with our understanding of binary subtraction.

// C++ code for Half Subtractor
#include <iostream>
using namespace std;

// Function to implement half subtractor
void HalfSubtractor(bool A, bool B, bool &D, bool &Bo)
{
    // XOR operation for difference
    D = A ^ B;
    
    // NOT-AND operation for borrow
    Bo = (!A) & B;
}

int main()
{
    bool A = 1;
    bool B = 0;
    bool D; // Difference
    bool Bo; // Borrow
    HalfSubtractor(A, B, D, Bo);
    cout<<"Difference = "<< D<<"\nBorrow = "<< Bo<< endl;
    return 0;
}

Executing the above C++ program with inputs A=1 and B=0 will give you the Difference = 1 and Borrow = 0, which corresponds to the binary subtraction of the inputs.

The half subtractor, while useful, is limited because it doesn't take into account any borrow from a previous stage of subtraction. To subtract binary numbers with more than one bit, we need a way to include the borrow from the previous bit's subtraction. This requirement leads us to the concept of a full subtractor.

3. The Full Subtractor

When we are dealing with binary numbers larger than one bit, we need to account for the borrow generated in the previous bit's subtraction. This is where the full subtractor comes into play. A full subtractor is a digital circuit that subtracts two binary digits and also accounts for an input borrow.

The full subtractor is constructed using XOR, AND, OR, and NOT gates. The addition of the OR gate assists in the calculation of the borrow output.

3.1 Full Subtractor: Design and Function

A full subtractor takes three inputs: A, B, and an input Borrow (Bi). It generates two outputs: a Difference (D) and an output Borrow (Bo). Here, the XOR operation is performed twice, first between A and B, and then between the result and Bi. The borrow is generated by three AND gates, two NOT gates, and an OR gate. The NOT gates invert A and B before they are given to the AND gates, and the outputs of these AND gates are then given to the OR gate, which generates Bo.

This design ensures that the borrow is forwarded when either of the following conditions is met: both A and B are 1 and Bi is 0, or one of A or B is 1 and Bi is also 1. This aligns with our understanding of binary subtraction.

// C++ code for Full Subtractor
#include <iostream>
using namespace std;

// Function to implement full subtractor
void FullSubtractor(bool A, bool B, bool Bi, bool &D, bool &Bo)
{
    // XOR operation for difference
    D = A ^ B ^ Bi;
    
    // NOT-AND-OR operation for borrow
    Bo = ((!A) & B) | ((A ^ B) & Bi);
}

int main()
{
    bool A = 1;
    bool B = 1;
    bool Bi = 1;
    bool D; // Difference
    bool Bo; // Borrow
    FullSubtractor(A, B, Bi, D, Bo);
    cout<<"Difference = "<< D<<"\nBorrow = "<< Bo<< endl;
    return 0;
}

Running the above C++ program with inputs A=1, B=1, and Bi=1 will give you the Difference = 1 and Borrow = 1, which corresponds to the binary subtraction of the inputs along with the input borrow.

The full subtractor is a significant advancement over the half subtractor as it can subtract larger binary numbers by cascading several full subtractors. However, the discussion of such subtractor networks is beyond the scope of this article.

4. Conclusion

Binary subtraction, while seemingly simple, poses significant challenges in digital systems. Subtractors, specifically half subtractors and full subtractors, offer an elegant solution to this problem. By using XOR, AND, OR, and NOT gates, these devices can perform binary subtraction efficiently, eliminating the need for binary-to-decimal conversions.

From our journey, we've learned:

Through our exploration of half and full subtractors, we have seen how these digital devices manage binary subtraction, demonstrating the power and elegance of digital electronics. With a firm grasp of these basic concepts, we are well-prepared to navigate the vast sea of binary data, ready to tackle the waves of 1s and 0s with confidence.

While subtractors are efficient at dealing with subtraction, there are instances where we need to perform addition of binary numbers. How do we tackle such situations? In the same way that subtractors assist us with subtraction, there exist digital circuits known as adders that simplify addition. Let us also venture into the realm of adders, uncovering the details of half adders and full adders, and understanding how they adeptly handle the task of binary addition.

As our journey into the world of digital electronics continues, we will explore more complex devices and systems, uncovering the intricacies and marvels of this fascinating field. In the next section, we will delve into the design and operation of more advanced subtractor networks, such as the borrow ripple subtractor, which allows for the subtraction of multi-bit binary numbers. The journey continues, and it promises to be a thrilling adventure!