C++ program to implement Half Adder
Prerequisite : Half Adder in Digital Logic
We are given with two inputs A and B. Our task is to implement Half Adder circuit and print the outputs sum and carry of two inputs.
The Half adder is a combinational circuit which add two1-bit binary numbers which are augend and addend to give the output value along with the carry. The half adder has two input states and two output states. The two outputs are Sum and Carry.
Here we have two inputs A, B and two outputs sum, carry. And the truth table for Half Adder is
Logical Expression :
Sum = A XOR B
Carry = A AND B
Input : A=0, B= 0
Output: Sum=0, Carry=0
Explanation: Here from logical expression Sum = A XOR B i.e 0 XOR 0 = 0, and Carry=A AND B i.e 0 AND 0 = 0.
Input : A=1, B= 0
Output: Sum=1, Carry=0
Explanation: Here from logical expression Sum=A XOR B i.e 1 XOR 0 =1 , Carry=A AND B i.e 1 AND 0 = 0.
- Initialize the variables Sum and Carry for storing outputs.
- First we will take two inputs A and B.
- By applying A XOR B we get the value of Sum.
- By applying A AND B we get the value of Carry.
Sum = 1 Carry = 0