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 to define structures? ·
What is the best style for code layout in c?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
Why is extern used in c?
What are the types of type specifiers?
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
what are the different storage classes in c?
The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?
If the size of int data type is two bytes, what is the range of signed int data type?
Can we access array using pointer in c language?
What is the difference between array_name and &array_name?
What is c basic?
Explain what is the difference between a string and an array?
what will be the output for the following main() { printf("hi" "hello"); }
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor