Given a modulo-n environment, and given that
, there is an
infinite number integers that are congruent modulo n. Namely,
the set of
is called
the equivalence class of
. For example, the equivalence class of 2
congruent to 3 is
. Another
notation is
, module-n is assumed in the ``hat''
notation. The equivalence class of the integer
is also called
the congruence class or reside class of
modulo
.
Modular mathematics is congruent with respect to the addition and
multiplication operators. This means that
.
In computer programming, modular math is used all the time. This is because of
the fixed width representation of integers. For example, let consider
16-bit integer. The value
and
are both represented as
0000 0000 0000 0001
in binary.
The more interesting case is how signed numbers are represented. Given that
we have using 16-bit integers, we are still using modulo 65536 operators.
However,
,
and etc. This is why -1 as a signed 16-bit integer has the same binary
representation as 65535 as an unsigned 16-bit integer.
Also interestingly, 2's complement can be used as negation. This is because
the negation operator can be defined as follows:
. In
modulo-65536 mathematics,
. Consequently, the
negation of a value
is
(because modular mathematics is congruent with respect to addition and
subtraction). The two's complement of
can be defined as
``bitwise not of
plus 1'', but it is also simply
. Hence, two's complement (n-bit) and negation are modulo-
congruent.