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

Why is c called "mother" language?

851


What does typedef struct mean?

651


Why is extern used in c?

609


Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.

1617


What is the difference between constant pointer and constant variable?

742






c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

606


Where are local variables stored in c?

567


formula to convert 2500mmh2o into m3/hr

491


What is function prototype in c language?

606


What is difference between union and structure in c?

568


What is pass by value in c?

591


What is the process of writing the null pointer?

605


How can I pad a string to a known length?

607


What are the two types of structure?

567


How can I access an I o board directly?

618