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
What is adt in c programming?
Disadvantages of C language.
cavium networks written test pattern ..
What is the general form of #line preprocessor?
How is a null pointer different from a dangling pointer?
what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?
How do you search data in a data file using random access method?
How can I ensure that integer arithmetic doesnt overflow?
What is difference between function overloading and operator overloading?
How do you override a defined macro?
illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question
Explain what is the benefit of using const for declaring constants?
What are pointers?
Why can’t we compare structures?
What are the preprocessor categories?