XOR associative property in parity calculation

515 Views Asked by At

So I am trying to determine the parity of an 8 bit word. Parity means that if the number of 1's in the word is odd the parity=1 and if number of one's is even parity=0. The word I am trying to determine the parity of is x= 11010111. Can someone explain why the parity of (1101) XORed with (0111) will have the same parity as 11010111? I understand XOR is associative but I dont understand how I can use that property to solve this problem.

1

There are 1 best solutions below

0
On BEST ANSWER

It is because XOR does work like a parity function: $X \ XOR \ Y = 1 $ iff exactly one of $X$ and $Y$ is $1$

So, where the parity of $1101$ is $X$, and the parity of $0111$ is $Y$, the parity of $11010111$ is $X \ XOR \ Y$, because you have an odd number of $1$'s in $11010111$ if and only if exactly one of $1101$ and $0111$ has an od number of $1$'s i.e if and only if exactly one of $1101$ and $0111$ has a parity of $1$.

Of course, we can similarly note that $11010111$ has a parity of $1$ iff exactly one of $110$ and $10111$ has a parity of $1$. That is, we can break the string in two at any place, and say the parity of the whole string is the same as the $XOR$ of the parities of the two parts. And that observation corresponds to the $XOR$ being associative.