Skip to content

Number System and Codes

2’S Complement, BCD Code, XS-3 Code, Gray Code

Section titled “2’S Complement, BCD Code, XS-3 Code, Gray Code”
  • For a number system with base n, n’s complement of a number is obtained by subtracting the number from nᵏ, where k = number of digits.
  • Formula
    n’s complement of X = nᵏ − X
  • Types
    • Binary (n = 2) → 2’s complement
    • Decimal (n = 10) → 10’s complement
    • Octal (n = 8) → 8’s complement
    • Hexadecimal (n = 16) → 16’s complement
  • Relation with (n−1)’s complementn’s complement = (n−1)’s complement + 1
  • Use
    • Subtraction using addition
    • Representation of negative numbers
  • Example (Decimal) Number = 275 10’s complement = 1000 − 275 = 725
  • Example (Binary)
    Number = 1010
    2’s complement = 0101 + 1 = 0110

Definition: Binary number representation for signed integers where negative numbers are obtained by taking the 1’s complement and adding 1. Use: Simplifies subtraction in digital systems. Steps (for negative numbers):

  1. Write the number in binary.
  2. Take 1’s complement (invert bits).
  3. Add 1 to the result.

Example (–5 in 8-bit):

+5 = 00000101
1's = 11111010
+1 = 11111011 → –5

Excess-3 is mainly used for self-complementing decimal arithmetic, not primarily for error detection.

Definition: A self-complementary decimal code obtained by adding 3 to each decimal digit and converting to 4-bit binary.

Use: self-complementing decimal arithmetic.

Example table:

DecimalBinaryExcess-3
000000011 (3)
100010100 (4)
200100101 (5)
300110110 (6)
401000111 (7)
501011000 (8)
601101001 (9)
701111010 (10)
810001011 (11)
910011100 (12)

Definition: Represents each decimal digit separately in binary (4 bits per digit).
Use: Digital displays, calculators.

Example:

5 9
Decimal 59 = (0101 1001) in BCD

Definition: A binary code where consecutive values differ by only 1 bit (minimizes errors in transitions).
Use: Position encoders, error reduction.

Example (3-bit Gray code):

DecimalBinaryGray
0000000
1001001
2010011
3011010
4100110
5101111
6110101
7111100

Excess-3 code is a non-weighted, self-complementary decimal code obtained by adding 3 to each decimal digit and then converting the result into 4-bit binary.

It is called “Excess-3” because:

Code = Decimal Digit + 3

Formula

XS-3 Code = Binary of (Decimal Digit + 3)

Steps to Find Excess-3 Code :

  1. Take the decimal digit
  2. Add 3 to it
  3. Convert the result into 4-bit binary

Excess-3 Code Table :

DecimalDecimal + 3Excess-3 Code
030011
140100
250101
360110
470111
581000
691001
7101010
8111011
9121100

Example 1: Decimal 2

2 + 3 = 5
Binary(5) = 0101

Excess-3 Code:

0101

Example 2: Decimal 7

7 + 3 = 10
Binary(10) = 1010

Excess-3 Code:

1010

Example 3: Decimal Number 59

Separate each decimal digit: ⭐

5 → 5 + 3 = 8 → 1000
9 → 9 + 3 = 12 → 1100

So:

59 = 1000 1100 (XS-3)

1. Non-Weighted Code

There are no fixed positional weights like:

8, 4, 2, 1

So XS-3 is a non-weighted code.

2. Self-Complementary Code

1’s complement of an XS-3 number gives XS-3 representation of the 9’s complement decimal digit.

Example:

Decimal 2 → XS-3 = 0101
1’s complement = 1010
1010 = XS-3 of 7

Since:

9 − 2 = 7

Hence XS-3 is self-complementary.

3. Uses 4 Bits

Each decimal digit is represented using 4 bits.

  1. Simplifies Decimal Subtraction Due to self-complementary property, subtraction becomes easier.

  2. Used in Decimal Arithmetic Useful in:

    • Adders
    • Subtractors
    • Digital arithmetic circuits
  3. Reduces Transition Errors Some invalid combinations help identify errors in circuits.

  4. Useful in Digital Electronics Used in:

    • Digital systems
    • Calculators
    • Arithmetic logic circuits
FeatureBCDExcess-3
TypeWeightedNon-weighted
RepresentationActual binaryBinary after adding 3
Decimal 000000011
Decimal 501011000
Self-ComplementaryNoYes