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
Is it better to use a macro or a function?
What does struct node * mean?
Describe the steps to insert data into a singly linked list.
Explain the array representation of a binary tree in C.
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
What is c mainly used for?
how is the examination pattern?
What is the use of getchar functions?
i have a written test for microland please give me test pattern
Explain which function in c can be used to append a string to another string?
Write a program to print fibonacci series without using recursion?
What is a c token and types of c tokens?
Is there anything like an ifdef for typedefs?
Can an array be an Ivalue?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......