c programming of binary addition of two binary numbers

Answer Posted / pramod yadav

#include<iostream.h>
#include<conio.h>
#define HIGH 1
#define LOW 0

class binary
{
public:
long c[8];
long CARRY;
binary()
{
CARRY=0;
for(int i=0;i<8;i++)
c[i]=0;
}
};
int main()
{
binary bin;
long i,n,a,b,k,m,A;
clrscr();
n=7;
cout<<"\nEnter the value of a&b in Decimal :";
cin>>a>>b;
for(i=0;i<8;i++)
{
k=((a>>i)&1);
m=((b>>i)&1);
if(!(bin.CARRY^HIGH))
{
bin.c[n]=((bin.CARRY^k)^m);
if(!(k^HIGH)||!(m^HIGH))
bin.CARRY=1;
else
bin.CARRY=0;
}
else if(!(k^HIGH) && !(m^HIGH))
{
bin.CARRY=1;
bin.c[n]=k^m;
}
else if(!(k^LOW)||!(m^LOW))
{
if(!(bin.CARRY^HIGH))
{
bin.c[n]=((bin.CARRY^k)^m);
bin.CARRY=0;
}
else
bin.c[n]=k^m;
}
n--;
}
cout<<"Addition of Two Binary No. is";
for(i=0;i<8;i++)
cout<<bin.c[i];
getch();
return 0;
}

Is This Answer Correct ?    7 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you have any idea how to compare array with pointer in c?

612


Hai what is the different types of versions and their differences

1495


What are the types of pointers?

608


What is the deal on sprintf_s return value?

647


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

622






"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above

618


explain what is an endless loop?

615


Is there any data type in c with variable size?

638


Explain how do you list a file’s date and time?

623


Why n++ execute faster than n+1 ?

1864


What is the advantage of c?

615


Should a function contain a return statement if it does not return a value?

603


What are the advantages of using new operator as compared to the function malloc ()?

762


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

733


will u please send me the placement papers to my mail???????????????????

1369