luoheng
10/12/2019 - 2:36 AM

bitwiseComplement

func bitwiseComplement(N int) int {
    if N == 0 {
        return 1
    }
    bits, n := uint(0), N
    for n != 0 {
        bits++
        n >>= 1
    }
    return (1 << bits) - N - 1
}