PROJECTENGRAM

COMPLEMENTS

Tags: #◇Computer Science #◇CSARCH1 #◇Computer Architecture #◇Data Representation #◇Complements


Complements

◇Overview

This module discusses how to represent different types of complements for any number system and how to perform subtraction using addition and complements. Complements are used in digital computers for logic manipulation and to simplify subtraction operations.

◇Types of Complements

For each base-rr system, there are two types of complements:

  1. Diminished Radix Complement: (r−1)(r-1)'s complement.
    • Binary (r=2r=2): 1's complement.
    • Decimal (r=10r=10): 9's complement.
  2. Radix Complement: rr's complement.
    • Binary (r=2r=2): 2's complement.
    • Decimal (r=10r=10): 10's complement.

◇Important Formulas

Diminished Radix Complement ((r−1)(r-1)'s complement)

Given a number NN in base rr having nn digits:
(rn−1)−N(r^n - 1) - N

  • Example: 9's complement of 1230101230_{10} (r=10,n=4r=10, n=4):
    • (104−1)−1230=9999−1230=876910(10^4 - 1) - 1230 = 9999 - 1230 = 8769_{10}
  • Example: 1's complement of 011020110_2 (r=2,n=4r=2, n=4):
    • (24−1)−0110=1111−0110=10012(2^4 - 1) - 0110 = 1111 - 0110 = 1001_2

Radix Complement (rr's complement)

Given a number NN in base rr having nn digits:
rn−Nfor N≠0, and 0 for N=0r^n - N \quad \text{for } N \neq 0, \text{ and } 0 \text{ for } N = 0

  • Practically, this is equivalent to: (r−1)(r-1)'s complement + 1.
  • Example: 10's complement of 1230101230_{10}:
    • 9's complement is 8769, plus 1 = 8770108770_{10}.
  • Example: 2's complement of 011020110_2:
    • 1's complement is 1001, plus 1 = 101021010_2.

◇Subtraction with Complements

Subtraction of two nn-digit unsigned numbers (M−NM - N) in base rr:

  1. Add the minuend MM to the rr's complement of the subtrahend NN.
  2. If M≥NM \geq N: The sum will produce an end carry. Discard the carry. The remaining result is M−NM - N.
  3. If M<NM < N: The sum produces no end carry. The result is the rr's complement of (M−N)(M - N). To view the answer in a familiar format, take the rr's complement of the sum and place a negative sign in front (though negative numbers technically don't exist for strictly unsigned formats).

Worked Examples

Example 1: Using 10's complement, perform 72532−325072532 - 3250

  • Pad NN to match the number of digits in MM: N=03250N = 03250.
  • M=72532M = 72532
  • 10's complement of N=96750N = 96750
  • M+N′=72532+96750=169282M + N' = 72532 + 96750 = 169282
  • Discard end carry -> 6928269282

Example 2: Using 10's complement, perform 3250−725323250 - 72532

  • M=03250M = 03250
  • 10's complement of N=27468N = 27468
  • M+N′=03250+27468=30718M + N' = 03250 + 27468 = 30718
  • No carry -> Take 10's complement of 3071830718 and add negative sign: −69282-69282

Example 3: Using 2's complement, perform 10101002−100001121010100_2 - 1000011_2

  • M=1010100M = 1010100
  • 2's complement of N=0111101N = 0111101
  • M+N′=1010100+0111101=10010001M + N' = 1010100 + 0111101 = 10010001
  • Discard end carry -> 001000120010001_2

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

What is the 9's complement of the decimal number 1230?

Q2

The radix complement of a number in base r is equivalent to:

Q3

What is the 1's complement of the binary number 0110?

Q4

What is the 2's complement of the binary number 1111?

Q5

What is the 10's complement of the decimal number 725?

Q6

When performing subtraction M - N using r's complement, what indicates that M is less than N?

Q7

What is the 2's complement of the binary number 0110?

Q8

What is the primary purpose of using complements in digital computers?

Q9

What is the (r-1)'s complement of 1100 in base 8 (octal)?

Q10

If M = 15 and N = 14, what is the result of adding M to the 10's complement of N (using 2 digits)?