Number of Bit Flips Problem Statement

Ninja is practicing binary representations and stumbled upon an interesting problem. Given two numbers 'A' and 'B', you are required to determine how many bits need to be flipped in 'B' to convert it to 'A'.

Help Ninja by finding the number of bit flips required.

Input:

T  // an integer representing the number of test cases.
For each test case, two integers A and B are provided.

Output:

Output the number of bit flips required for each test case on a new line.

Example:

Input:
A = 13, B = 7
Output:
2
Explanation:

The binary representation of A is 1101 and B is 0111. Two bits differ between these numbers, hence the number of flips needed is 2.

Constraints:

  • 1 <= T <= 10
  • 1 <= A, B <= 10^9
  • Time limit: 1 sec
AnswerBot
10d

Calculate the number of bit flips required to convert one number to another in binary representation.

  • Convert both numbers to binary representation

  • Count the number of differing bits between the two num...read more

Help your peers!
Add answer anonymously...
Info Edge Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter