top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

how to write a program for half adder in C++?

+2 votes
2,036 views
how to write a program for half adder in C++?
posted Apr 7, 2014 by Simranjeet Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

a and b must be bits....i.e 0 and/or 1

void halfadder(int a, int b)
{
    carry=a*b
    sum=a *  ~b + b * ~a    // or use a ^ b
}

void fulladder(int a, int b ,int carryin)
{
    carryout=a * b+b * carryin+ a * carryin
    sum=  a ^ b ^ c     
    // you can convert into sop form 
}
answer Apr 7, 2014 by Prakash
...