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
How can I call a function with an argument list built up at run time?
What are the types of assignment statements?
a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above
Can we compile a program without main() function?
What are the advantages of the functions?
What is cohesion and coupling in c?
What is variable initialization and why is it important?
Explain what is a static function?
What is the best way to store flag values in a program?
Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer
Is malloc memset faster than calloc?
Explain main function in c?
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
What does 4d mean in c?
What does s c mean on snapchat?