Two’s complement signed integers modulo $n$ lacks inverse for $-32768$: does addition still work

binarychinese remainder theoremelementary-number-theorymodular arithmetic

I have a computer program that needs to do addition using the int16_t type, i.e., signed 16-bit integers. Since this is a signed binary number, the largest positive value is $2^{15} – 1 = 32767$, expressed in binary as $0111111111111111_2$. When we add 1 to this, we get $1000000000000000_2$, or $-32768$ decimal. Further addition gives $1000000000000001_2 = -32767_{10}$, and so on. This means that $-32768$ does not have an additive inverse.

My question is: should I expect to be able to add and subtract numbers using signed integers modulo $2^{15}$, given that there is one element without an inverse and hence the set is not a group under addition? I wrote a test program, and addition seems to work as expected, but I may be missing a case.

Best Answer

You actually have two values for each residue class $\bmod 32768$ in the $16$ bit signed integers. In all cases they differ by $32768$. In the case of $-32768$ the other member of the class is $0$. Normally one would express the numbers $\bmod 32768$ using the range $0-32767$, which is exactly the set of nonnegative integers you have. Each has an additive inverse with $0$ and $16384$ their own inverses.