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
Do you have any idea how to compare array with pointer in c?
Hai what is the different types of versions and their differences
What are the types of pointers?
What is the deal on sprintf_s return value?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above
explain what is an endless loop?
Is there any data type in c with variable size?
Explain how do you list a file’s date and time?
Why n++ execute faster than n+1 ?
What is the advantage of c?
Should a function contain a return statement if it does not return a value?
What are the advantages of using new operator as compared to the function malloc ()?
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
will u please send me the placement papers to my mail???????????????????