I've seen the complement of $A$ defined in three different ways in three different places:
- $$A’ = (A+1) \mod{2}$$
- $$f(A) = 1 - A$$
- $$NOT\ A = -A − 1$$
Are they all correct? If so, how does that work exactly?
I've seen the complement of $A$ defined in three different ways in three different places:
Are they all correct? If so, how does that work exactly?
On
$$A' = (A + 1) \bmod 2$$ is clearly intended to be the complement of a Boolean: i.e. it maps $0$ to $1$ and vice versa, and that's all.
$$f(A) = 1 - A$$ likewise maps $0$ to $1$ and vice versa. I don't believe it's intended to have a larger domain than $\{0,1\}$.
$$NOT A = -A - 1$$ is bitwise complement in a twos complement system: this means that on almost all modern computer processors it corresponds to a bitwise complement of a full word. Using an 8-bit word to keep the examples manageable, we represent $0$ as 00000000, $1$ as 00000001, etc. up to 127 as 01111111; and we represent $-1$ as 11111111, $-2$ as 11111110, etc. down to -128 as 10000000.
Note that $A=-A \pmod {2}$, so $1-A \equiv 1+A \equiv A+1 \pmod{2}$ and $1 \iff 2$.
Similarly, $-A-1 \equiv A+1 \pmod {2}$ so $3 \iff 1$.