Change xor to sum and bit mask