1322. Hamming Distance Between Two Integers

EasyBit ManipulationBit ManipulationHammingXOR

Given two non-negative integers a and b, return their Hamming distance: the number of bit positions at which the corresponding bits differ.

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

Output: Return the Hamming distance between a and b.

Examples

Example 1
Input: {"a":1,"b":4}
Output: 2
Explanation: 001 vs 100 differ in two positions -> 2.
Example 2
Input: {"a":3,"b":1}
Output: 1
Explanation: 011 vs 001 differ in one position -> 1.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →