• + 0 comments

    here is my Go solution

    func theGreatXor(x int64) int64 {
        if x & (x - 1) == 0 {
            return x - 1
        }
        var count uint
        var temp int64 = x
         
        for temp > 0 {
            temp = temp >> 1
            count++            
        }
        if count == 0{
            return 0
        } else{
            return 1 << (count - 1) - (x - (1 << (count - 1))) - 1    
        }
    
    }