Description
Given an integer x and an integer y, the Hamming distance between two integers is the number of positions where corresponding bits differ. Return the result as an integer.
Examples
Input:
x = 1, y = 4Output:
2Explanation:
0001 vs 0100 differ in 2 positions.
Input:
x = 0, y = 15Output:
4Explanation:
0000 vs 1111 differ in all 4 positions (bits 0, 1, 2, and 3).
Input:
x = 7, y = 7Output:
0Explanation:
0111 vs 0111 are identical, so no bits differ.
Constraints
- •
0 ≤ x, y ≤ 2³¹ - 1