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
application attempts to perform an operation?
Why calloc is better than malloc?
What is the difference between a function and a method in c?
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
What is memcpy() function?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What are pointers? What are different types of pointers?
Explain 'far' and 'near' pointers in c.
What is the function of volatile in c language?
What are the advantages of using macro in c language?
How can I determine whether a machines byte order is big-endian or little-endian?
How do you list files in a directory?
What is a structural principle?
What are the ways to a null pointer can use in c programming language?
what is reason of your company position's in india no. 1.