• + 0 comments

    Here is my Python solution!

    def theGreatXor(x):
        amount = 0
        greatest = int(math.log(x, 2))
        for num in range(greatest):
            if (2 ** num) ^ x > x:
                amount += 2 ** num
        if (2 ** greatest) ^ x > x:
            amount += x - 2 ** greatest
        return amount