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


Please Help Members By Posting Answers For Below Questions

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

727


How many keywords (reserve words) are in c?

625


Is swift based on c?

642


Does * p ++ increment p or what it points to?

621


Can you please explain the difference between exit() and _exit() function?

596






What is the difference between functions getch() and getche()?

625


how to write a c program to print list of fruits in alpabetical order?

1797


List some of the static data structures in C?

765


Explain how can you check to see whether a symbol is defined?

665


Why c is faster than c++?

637


How can you increase the size of a statically allocated array?

622


How can a program be made to print the line number where an error occurs?

654


What is indirection? How many levels of pointers can you have?

663


What is #include cctype?

582


Explain how can I manipulate strings of multibyte characters?

788