Complements of Numbers

Complements are used in digital computers to simplify the subtraction operation and for logical manipulation. There are two types of complements for each base-\(r\) system: the radix complement and the diminished radix complement. The first is referred to as the \(r\)’s complement and the second as the \((r - 1)\)’s complement.

If the original number \(N\) contains a radix point, the point should be removed temporarily in order to form the \(r\)’s or \((r - 1)\)’s complement. The radix point is then restored to the complemented number in the same relative position.

The complement of the complement restores the number to its original value.

Diminished Radix Complement

The \((r - 1)\)’s complement of a number \(N\) in base \(r\) having \(n\) digits is defined as

\(\boxed{N_{(r - 1)\textrm{'s complement}} = \left(r^n - 1\right) - N}\)

For decimal numbers, \(r = 10\) and \(r - 1 = 9\), so the \(9\)’s complement of \(N\) is \((10^n - 1) - N\). Since \(10^n - 1\) is a decimal number represented by \(n\) \(9\)’s, the \(9\)’s complement of a decimal number is obtained by subtracting each digit from \(9\).

For example, find the \(9\)’s complement of \(N = (546700)_{10}\)

\(\displaystyle N_{9\textrm{'s complement}} = \left(10^n - 1\right) - N = \left(10^6 - 1\right) - (546700)_{10}\)

\(\displaystyle N_{9\textrm{'s complement}} = (999999)_{10} - (546700)_{10} = (453299)_{10}\)

The \(9\)’s complement of \((546700)_{10}\) is \((453299)_{10}\)

For binary numbers, \(r = 2\) and \(r - 1 = 1\), so the \(1\)’s complement of \(N\) is \((2^n - 1) - N\). Since \(2^n - 1\) is a binary number represented by \(n\) \(1\)’s, the \(1\)’s complement of a binary number is obtained by subtracting each digit from \(1\). Therefore, the \(1\)’s complement of a binary number is formed by changing \(1\)’s to \(0\)’s and \(0\)’s to \(1\)’s.

For example, find the \(1\)’s complement of \(N = (1011000)_2\)

\(\displaystyle N_{1\textrm{'s complement}} = \left(2^n - 1\right) - N = \left(2^7 - 1\right) - (1011000)_2\)

\(\displaystyle N_{1\textrm{'s complement}} = (1111111)_2 - (1011000)_2 = (0100111)_2\)

The \(1\)’s complement of \((1011000)_2\) is \((0100111)_2\)

The \((r - 1)\)’s complement of octal or hexadecimal numbers is obtained by subtracting each digit from \(7\) or \(\mathrm{F}\) (decimal \(15\)), respectively.

Radix Complement

The \(r\)’s complement of a number \(N\) in base \(r\) having \(n\) digits is defined as

The \(r\)’s complement is obtained by adding \(1\) to the \((r - 1)\)’s complement,

\(\displaystyle N_{(r - 1)\textrm{'s complement}} + 1 = \left[\left(r^n - 1\right) - N\right] + 1 = r^n - N\)

\(\boxed{N_{r\textrm{'s complement}} = N_{(r - 1)\textrm{'s complement}} + 1 = r^n - N}\,,\quad\textit{for }N \neq 0\)

\(\boxed{N_{r\textrm{'s complement}} = N_{(r - 1)\textrm{'s complement}} + 1 = 0}\,,\quad\textit{for }N = 0\)

The \(r\)’s complement of \(N\) can be formed by leaving all least significant \(0\)’s unchanged, subtracting the first nonzero least significant digit from \(r\), and subtracting all higher significant digits from \(r - 1\).

For example,

The \(10\)’s complement of \((012398)_{10}\) is \((987602)_{10}\)

The \(10\)’s complement of \((246700)_{10}\) is \((753300)_{10}\)

The \(2\)’s complement of \((1101100)_2\) is \((0010100)_2\)

The \(2\)’s complement of \((0110111)_2\) is \((1001001)_2\)

Subtraction with Complements

In direct method of subtraction, \(1\) is borrowed from a higher significant position when the minuend digit is smaller than the subtrahend digit. However, when this method is implemented with digital hardware, the method is less efficient than the method that uses complements.

The subtraction of two n-digit unsigned numbers \(M - N\) in base \(r\) can be done as follows:

Add the minuend \(M\) to the \(r\)’s complement of the subtrahend \(N\). Mathematically,

\(\boxed{S = M + \left(r^n - N\right) = M - N + r^n}\)

If \(M \geq N\), the sum will produce an end carry \(r^n\), which can be discarded; what is left is the result \(M - N\).

If \(M < N\), the sum does not produce an end carry and is equal to \(r^n - (N - M)\), which is the \(r\)’s complement of \(N - M\). To obtain the answer in a familiar form, take the \(r\)’s complement of the sum and place a negative sign in front.

Links to this page
  • Signed Binary Numbers

    In the signed-complement system, a negative number is indicated by its complement. The signed-complement system can use either the \(1\)’s complement or the \(2\)’s complement, but the \(2\)’s complement is the most common.

    Note that negative numbers must be initially in \(2\)’s complement form and that if the sum obtained after the addition is negative, it is in \(2\)’s complement form. Any carry out of the sign-bit position is discarded, and negative results are automatically in \(2\)’s complement form.

  • Boolean Algebra

    NOT \(({}^{\prime})\): This operation is represented by a prime \(({}^{\prime})\) or an overline \((\overline{})\), also referred to as the complement operation, since it changes a \(1\) to \(0\) and a \(0\) to \(1\).

#digital #number