Write a program to display the no of bit difference between
any 2 given numbers
eg: Num1 will 12->1100
Num2 will 7->0111 the difference in bits are 2.
Answer Posted / banavathvishnu
int main()
{
int num1,num2;
int cnt = 0;
int temp1,temp2;
printf("enter 2 numbers \n");
scanf("%d %d",&num1,&num2);
while((num1!=0)||(num2!=0))
{
temp1= num1 & 0x01;
temp2 = num2 & 0x01;
if((temp1 ^ temp2)==1)
cnt++;
num1 = num1>>1;
num2 = num2>>1;
}
printf("difference is %d",cnt);
getch();
}
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What is memory leak in c?
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
What is the explanation for prototype function in c?
What is sizeof int?
What is selection sort in c?
Explain what will the preprocessor do for a program?
Is c call by value?
What are the restrictions of a modulus operator?
What is #include called?
When can a far pointer be used?
explain what are actual arguments?
please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com
how to make a scientific calculater ?
How can a program be made to print the name of a source file where an error occurs?
For what purpose null pointer used?