C++ code for half adder

Half adder is a simple combinational electronic circuit which can be formed by using XOR operation and the carry by AND operation. The su...

Half adder is a simple combinational electronic circuit which can be formed by using XOR operation and the carry by AND operation.
The sum of Half Adder circuit can be found using the XOR operation and the carry using the AND 
operation.
There are only three things to remember when dealing with electronic circuits:
0 + 0 = 0, 0 + 1 = 1 + 0 = 1, and 1 + 1 = 10.
    
1:  //c++ code to implement Half Adder  
2:  #include <iostream>  
3:  using namespace std;  
4:  int main()  
5:  {  
6:  int x,y,sum,carry;  
7:  cout<<"HALF ADDER IMPLEMNTATION!"<<endl;  
8:  cout<<endl;  
9:  cout<<"x|y|carry|sum"<<endl;  
10:  cout<<"-|-|-----|---"<<endl;  
11:  for(x=0;x<2;x++)  
12:      {  
13:  for(y=0;y<2;y++)  
14:       {  
15:  sum=!x&&y||x&&!y;  
16:  carry=x&&y;  
17:  cout<<""<<x<<"|"<<y<<"| "<<carry<<" |"<<sum<<endl;  
18:        }  
19:      }  
20:  cout<<endl<<endl;  
21:  return 0;  
22:  }  

Post a Comment

emo-but-icon

item