3

Number of Flips

Difficulty: EASY
Contributed By

Problem Statement

Ninja is learning the binary representation of the numbers. He wanted to practice the topic, so he picked a question. The problem statement says, two numbers, ‘A’ and ‘B’ are given. Find the number of bits of ‘B’ that should be flipped to convert it into ‘A’.Can you help Ninja to solve this problem?

You are given two integers, ‘A’ and ‘B’.Find the number of bits of ‘B’ that should be flipped to convert it into ‘A’.

For Example
If ‘A’ is 13(1101) and ‘B’ is 7(0111), The number of bits that should be flipped is 2(0111). 
Input Format:
The first line of the input contains an integer, 'T,’ denoting the number of test cases.

The first line of each test case contains two integers, ‘A’ and ‘B’.
Output Format:
For each test case, print ‘an integer corresponding to the minimum number of swaps required.

Print the output of each test case in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= ‘A’,’B’ <= 10^9.

Time limit: 1 sec
Sample Input 1:
2
13 7
15 20
Sample Output 1:
2
4
Explanation of sample input 1:
For the first test case,

The binary representation of 13 is 1101.
The binary representation of 7 is 0111.
So, we will change the 2nd and the 4th bit from the right to convert B into A.
Hence, the answer is 2. 


For the second test case:

The binary representation of 20 is 10100.
The binary representation of 15 is 01111.
So, we will change the 1st,2nd,4th, and 5th bit from the right to convert B into A.
Hence, the answer is 4. 
Sample Input 2:
2
3 10
6 4
Sample Output 2:
2
1
Reset Code
Full screen
copy-code
Console