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 const keyword in c?
How does normalization of huge pointer works?
What are the application of c?
Explain the difference between malloc() and calloc() in c?
How do you print only part of a string?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm
Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?
Explain how are portions of a program disabled in demo versions?
Compare array data type to pointer data type
What are dangling pointers? How are dangling pointers different from memory leaks?
What is bss in c?
What are run-time errors?
Write a program to print “hello world” without using semicolon?
What is pivot in c?
What does == mean in texting?