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
4mo

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!
Select
Add answer anonymously...

Top Senior Software Engineer Interview Questions Asked at Info Edge

Q. Develop a reusable modal component using React.
Q. Write a program to swap the kth node from the beginning and the kth node from th...read more
Q. Given two strings s and t, return the minimum window in s which will contain all...read more
Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits