Sum vs XOR

  • + 0 comments
    def sumXor(n):
        # So basically, criteria is met when all bits are flipped to 1's for an n xor x 
        #and none are flipped to zeros
        #Meaning any non-1 in n is an option for x values, fortunately x is never greater than n making
        #this a lot easier
        if n==0:return 1
        return 2**sum([True if i=='0' else False for i in format(n,'0b')])