i need to add function to Find the Sum of two Binary Numbers #include #include // function to convert decimal into binary int dec2binary(int N) { int R, B = 1, Output = 0; while (N > 0) { R = N % 2; Output = Output + R * B; N = N / 2; B = B * 10; } return Output; } // function to convert binary to decimal int binary2decimal(long long n) { int dec = 0, i = 0, rem; while (n!=0) { rem = n % 10; n /= 10; dec += rem * pow(2, i); ++i; } return dec; } char Carryout=0; char fulladder(char A ,char B,char Carryin) { Carryout=(A&B)||(Carryin&(A^B)); return (A^B)^Carryin; } int main() { int i,j,k; int result; int m, n, bin1, bin2; printf("Enter two decimal numbers: "); scanf("%d%d", &m, &n); bin1 = dec2binary(m); bin2 = dec2binary(n); printf("Binary equivalent of %d is %08d\n", m, bin1); printf("Binary equivalent of %d is %08d\n\n", n, bin2); printf("A B Carryin | Sum Carryout\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { for(k=0;k<2;k++) { result=fulladder(i,j,k); printf("%d %d %d | ",i,j,k); printf("%d %d\n",result,Carryout); } } } return 0; } Output Sample Enter two decimal numbers: 78 204 Binary equivalent A of 20 is 1: 1110000 Binary equivalent B of 23 is 1: 1001100 A B Carryin | Sum Carryout 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 Sum of A and B binary number: 10010110 Converted to decimal: 150
i need to add function to Find the Sum of two Binary Numbers
#include <stdio.h>
#include <math.h>
// function to convert decimal into binary
int dec2binary(int N)
{
int R, B = 1, Output = 0;
while (N > 0)
{
R = N % 2;
Output = Output + R * B;
N = N / 2;
B = B * 10;
}
return Output;
}
// function to convert binary to decimal
int binary2decimal(long long n) {
int dec = 0, i = 0, rem;
while (n!=0) {
rem = n % 10;
n /= 10;
dec += rem * pow(2, i);
++i;
}
return dec;
}
char Carryout=0;
char fulladder(char A ,char B,char Carryin)
{
Carryout=(A&B)||(Carryin&(A^B));
return (A^B)^Carryin;
}
int main()
{
int i,j,k;
int result;
int m, n, bin1, bin2;
printf("Enter two decimal numbers: ");
scanf("%d%d", &m, &n);
bin1 = dec2binary(m);
bin2 = dec2binary(n);
printf("Binary equivalent of %d is %08d\n", m, bin1);
printf("Binary equivalent of %d is %08d\n\n", n, bin2);
printf("A B Carryin | Sum Carryout\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
result=fulladder(i,j,k);
printf("%d %d %d | ",i,j,k);
printf("%d %d\n",result,Carryout);
}
}
}
return 0;
}
Output Sample
Enter two decimal numbers: 78 204
Binary equivalent A of 20 is 1: 1110000
Binary equivalent B of 23 is 1: 1001100
A B Carryin | Sum Carryout
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
Sum of A and B binary number: 10010110
Converted to decimal: 150
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)