Two's complement is a fixed-width encoding of integers. With bits, a value
in the range
is encoded by the ordinary
-digit binary
representation of the residue of
modulo
. A negative integer
can therefore be encoded by taking
the ones' complement of the bit
string for
and then performing addition of 1. For example, the
8-bit representation of
is
.
Two's complement has a single representation of zero. Its asymmetric range contains but not
. addition is performed
modulo
, so a carry beyond the leading
digit is discarded. For example, the calculation for
is
The numeral spelling "2's complement" is common in engineering. The hyphenated form "two's-complement" is used attributively, as in "two's-complement representation," while the unpunctuated spelling "twos complement" occurs in identifiers or typography that omits apostrophes. These forms denote the same representation.