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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY