We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
After we calculate a few examples of addition and XOR on paper, we will conclude that x+n = x xor n only if there is no carry forwarded to the next digit (in binary) when we do addition. In other words, we are only interested in x's which don't have 1s in a position where n has it. The answer is then the number of numbers we can create by filling with either 0 or 1 the 0s in n. To calculate this, we firstly count the numbers of 0s in n. The final answer is the 2 to the power of the # of 0s in n.
Sum vs XOR
You are viewing a single comment's thread. Return to all comments →
After we calculate a few examples of addition and XOR on paper, we will conclude that x+n = x xor n only if there is no carry forwarded to the next digit (in binary) when we do addition. In other words, we are only interested in x's which don't have 1s in a position where n has it. The answer is then the number of numbers we can create by filling with either 0 or 1 the 0s in n. To calculate this, we firstly count the numbers of 0s in n. The final answer is the 2 to the power of the # of 0s in n.