Reputation: 793
Is this always true?
We have two strings of bits s1 and s2, the XOR value between them is S, imagine we change n bits in s1 (let's call it s1' now), then let's call S' the XOR value between s1' and s2, is it true S is equal to S' but n bits?
s1 = 100001;
s2 = 100011;
S = 000010;
Let's change 2 bits in s1 so now
s1' = 100111;
S' = 000100;
S and S' differ only for 2 bits. But does this work always? I don't know much about XOR's properties and basic computer science in general.
Upvotes: 0
Views: 97
Reputation: 28219
Yes XOR doesn't have any carry. So the number of bits you change in one of the inputs will be the number of output bits changed.
INPUT OUTPUT
A B A XOR B
0 0 0
0 1 1
1 0 1
1 1 0
Upvotes: 1