use xor instead of minus when doing calculation with mask