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


Please Help Members By Posting Answers For Below Questions

swap 2 numbers without using third variable?

656


What is mean by data types in c?

545


Write a program to print “hello world” without using semicolon?

665


2) Write a program that will help Air Traffic Control for an airport to view the sequence of flights ready for take-off. The airport can accommodate 10 flights waiting for take-off at any point in time. Each flight has a unique 3 digit numeric identifier.  Each time a flight takes-off, Air Traffic Control adds a flight to the waitlist. Each time a flight is added to the waitlist, the list of flights waiting to take-off must be displayed.  When a flight is cleared for take-off, Air Traffic Control removes the flight from the waitlist. Each time a flight takes-off, the list of flights waiting to take-off must be displayed.  Sequence of take-off is the sequence of addition to the waitlist

2511


What is the process to create increment and decrement stamen in c?

581






What is struct node in c?

612


Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above

654


When is a “switch” statement preferable over an “if” statement?

639


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

615


Why pointers are used in c?

578


An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

643


What is huge pointer in c?

574


Why is c known as a mother language?

738


How do you write a program which produces its own source code as output?

599


How to declare pointer variables?

677