HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajor

Confused about XORing and addition modulo $2$

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
xoringadditionconfusedaboutandmodulo

Problem

It's my understanding that when you XOR something, the result is the sum of the two numbers mod $2$.

Why then does $4 \oplus 2 = 6$ and not $0$? $4+2=6$, $6%2$ doesn't equal $6$. I must be missing something about what "addition modulo 2" means, but what?


100 // 4


010 // XOR against 2


110 = 6 // why not zero if xor = sum mod 2?

Solution

The confusion here stems from a missing word. A correct statement is "The result of XORing two bits is the same as that of adding those two bits mod 2."

For example, $(0+1)\bmod 2 = 1\bmod 2 = 1=(0\text{ XOR }1)$

and

$(1+1) \bmod 2= 2\bmod 2 = 0 =(1\text{ XOR }1)$

Context

StackExchange Computer Science Q#41664, answer score: 26

Revisions (0)

No revisions yet.