c programming of binary addition of two binary numbers
Answer Posted / vignesh1988i
the below program is for getting two numbers as input
(decimal format) and then the below program will convert in
binary and add WITHOUT ANY ARITHMETIC OPERATORS.....
#include<stdio.h>
#include<conio.h>
#define HIGH 1
#define LOW 0
void main()
{
long c[32],i,n,a,b,k,m,A,CARRY=0;
clrscr();
n=31;
printf("enter the value of a&b:");
scanf("%ld%ld",&a,&b);
for(i=0;i<32;i++)
{
k=((a>>i)&1);
m=((b>>i)&1);
if(!(CARRY^HIGH))
{
c[n]=((CARRY^k)^m);
if(!(k^HIGH)||!(m^HIGH))
CARRY=1;
else
CARRY=0;
}
else if(!(k^HIGH) && !(m^HIGH))
{
CARRY=1;
c[n]=k^m;
}
else if(!(k^LOW)||!(m^LOW))
{
if(!(CARRY^HIGH))
{
c[n]=((CARRY^k)^m);
CARRY=0;
}
else
c[n]=k^m;
}
n--;
}
for(i=0;i<32;i++)
printf("%d",c[i]);
getch();
}
thank u
Is This Answer Correct ? | 30 Yes | 12 No |
Post New Answer View All Answers
a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none
How many keywords (reserve words) are in c?
Is swift based on c?
Does * p ++ increment p or what it points to?
Can you please explain the difference between exit() and _exit() function?
What is the difference between functions getch() and getche()?
how to write a c program to print list of fruits in alpabetical order?
List some of the static data structures in C?
Explain how can you check to see whether a symbol is defined?
Why c is faster than c++?
How can you increase the size of a statically allocated array?
How can a program be made to print the line number where an error occurs?
What is indirection? How many levels of pointers can you have?
What is #include cctype?
Explain how can I manipulate strings of multibyte characters?