Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Take any 2 numbers and converts into binary format and find the number of bits flipped in between 1st and 2nd number?

+1 vote
asked Feb 24, 2020 by anonymous
For example
2 numbers are 7, 10
Binary digits of 7 is :  00000111
Binary digits of 10 is :00001010
Output is :3. Because Here 3 digits are  flipped.

1 Answer

0 votes
answered Feb 28, 2020 by anonymous
int temp = 0;

int count = 0;

while both numbers are not 0, temp = first & second. If temp == 0 the count++ (if not then don't increase count). Then right shift both numbers by 1 bit and continue until both are 0. Output the count.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...