1315. Count Bits to Convert A to B

EasyBit ManipulationBit ManipulationHammingXOR

Given two non-negative integers a and b, return the number of bit flips needed to transform a into b. This equals the number of positions where a and b differ.

Input: A JSON object {"a": <integer>, "b": <integer>}.

Output: Return the count of differing bits between a and b.

Examples

Example 1
Input: {"a":10,"b":20}
Output: 4
Explanation: 10 ^ 20 = 30 = 11110, four set bits -> 4.
Example 2
Input: {"a":7,"b":7}
Output: 0
Explanation: Identical values need no flips -> 0.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →