hamming distance

func hammingDistance(x int, y int) int {
    z := x^y
    var count int
    for{

        res := z&1
        if res == 1{
            count++
        }
        z = z>>1
        if z==0{
            break
        }
    }
    return count
}

你可能感兴趣的:(hamming distance)