Python program to implement Half Subtractor
Prerequisite: Half Subtractor in Digital Logic
Given two inputs of Half Adder A, B. The task is to implement the Half Subtractor circuit and Print output i.e Difference and Borrow of two inputs.
The half subtractor is also a building block for subtracting two binary numbers. It has two inputs and two outputs. This circuit is used to subtract two single bit binary numbers A and B. The difference and borrow are the two output states of the half subtractor.
Input: A=0; B=1
Output: Difference: 1
Explanation: According to logical expression Difference=A XOR B i.e 0 XOR 1 =1, Borrow=Ā AND B i.e 1 AND 1 =1
Input: A=1; B=1
Output: Difference: 0
Difference = A XOR B Borrow = Ā AND B
- We take two inputs A and B.
- XOR operation on A and B gives the value of the Difference.
- AND operation on Ā and B gives the value of Borrow.
Difference: 1 Borrow: 1