Full Adder
Truth Table:
Circuit Diagram:
Sum = A XOR B XOR C_in
C_out = A.B + B.C_in + A.C_in
C_out = A.B + B.C_in + A.C_in
Program in C:
#include <stdio.h> typedef char bit; bit Cout=0; bit fulladd(bit A ,bit B,bit Cin){ Cout=(A&B)||(Cin&(A^B)); return (A^B)^Cin; } int main() { int i,j,k; int result; printf("A B Cin | S Cout\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { for(k=0;k<2;k++) { result=fulladd(i,j,k); printf("%d %d %d | ",i,j,k); printf("%d %d\n",result,Cout); } } } return 0; }
Output:
A B Cin | S Cout
0 0 0 | 0 0
0 0 1 | 1 0
0 1 0 | 1 0
0 1 1 | 0 1
1 0 0 | 1 0
1 0 1 | 0 1
1 1 0 | 0 1
1 1 1 | 1 1
--------------------------------
Process exited after 0.1661 seconds with return value 0
Press any key to continue . . .
Program in C++:
#include <iostream> using namespace std; typedef char bit; bit fulladd(bit A ,bit B,bit Cin,bit D){ if(D==0) return (A&B)||(Cin&(A^B)); else return (A^B)^Cin; } int main() { int i,j,k; int result,Cout; cout<<"A B Cin | S Cout\n"; for(i=0;i<2;i++) { for(j=0;j<2;j++) { for(k=0;k<2;k++) { Cout=fulladd(i,j,k,0); result=fulladd(i,j,k,1); cout<<i<<" "<<j<<" "<<k<<" | "; cout<<result<<" "<<Cout<<"\n"; } } } return 0; }
Output:
A B Cin | S Cout
0 0 0 | 0 0
0 0 1 | 1 0
0 1 0 | 1 0
0 1 1 | 0 1
1 0 0 | 1 0
1 0 1 | 0 1
1 1 0 | 0 1
1 1 1 | 1 1
--------------------------------
Process exited after 0.1661 seconds with return value 0
Press any key to continue . . .
Comments :
Post a Comment