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
What is the right type to use for boolean values in c? Is there a standard type?
What is the difference between #include
What are the different types of C instructions?
string reverse using recursion
What happens if a header file is included twice?
How a string is stored in c?
What is the mean of function?
What's the right way to use errno?
How can I read a binary data file properly?
Find MAXIMUM of three distinct integers using a single C statement
Is it better to use malloc() or calloc()?
What is 2c dna?
What is the difference between class and object in c?
What are the preprocessor categories?
Describe wild pointers in c?