x
와 y
를 XOR 한다.countOne
: XOR의 결괏값 중 1의 비트 수xor
이 0이 아닌동안 반복xor
의 첫 비트가 1이라면 1추가 (1의 비트 수 ++)xor
을 shift하여 다음 비트 검사function hammingDistance(x: number, y: number): number {
let xor = x ^ y
let countOne = 0
while(xor) {
countOne += xor & 1
xor = xor >> 1
}
return countOne
};