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
Why is c called "mother" language?
What does typedef struct mean?
Why is extern used in c?
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.
What is the difference between constant pointer and constant variable?
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
Where are local variables stored in c?
formula to convert 2500mmh2o into m3/hr
What is function prototype in c language?
What is difference between union and structure in c?
What is pass by value in c?
What is the process of writing the null pointer?
How can I pad a string to a known length?
What are the two types of structure?
How can I access an I o board directly?