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”1. N’s Complement
Section titled “1. N’s Complement”- 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 complement ⭐ n’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
2’s Complement
Section titled “2’s Complement”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):
- Write the number in binary.
- Take 1’s complement (invert bits).
- Add 1 to the result.
Example (–5 in 8-bit):
+5 = 000001011's = 11111010+1 = 11111011 → –5Excess-3 Code
Section titled “Excess-3 Code”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:
| Decimal | Binary | Excess-3 |
|---|---|---|
| 0 | 0000 | 0011 (3) |
| 1 | 0001 | 0100 (4) |
| 2 | 0010 | 0101 (5) |
| 3 | 0011 | 0110 (6) |
| 4 | 0100 | 0111 (7) |
| 5 | 0101 | 1000 (8) |
| 6 | 0110 | 1001 (9) |
| 7 | 0111 | 1010 (10) |
| 8 | 1000 | 1011 (11) |
| 9 | 1001 | 1100 (12) |
BCD (Binary Coded Decimal)
Section titled “BCD (Binary Coded Decimal)”Definition: Represents each decimal digit separately in binary (4 bits per digit).
Use: Digital displays, calculators.
Example:
5 9Decimal 59 = (0101 1001) in BCDGray Code
Section titled “Gray Code”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):
| Decimal | Binary | Gray |
|---|---|---|
| 0 | 000 | 000 |
| 1 | 001 | 001 |
| 2 | 010 | 011 |
| 3 | 011 | 010 |
| 4 | 100 | 110 |
| 5 | 101 | 111 |
| 6 | 110 | 101 |
| 7 | 111 | 100 |
Excess-3 Code (XS-3 Code)
Section titled “Excess-3 Code (XS-3 Code)”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 + 3Formula
XS-3 Code = Binary of (Decimal Digit + 3)Steps to Find Excess-3 Code :
- Take the decimal digit
- Add 3 to it
- Convert the result into 4-bit binary
Excess-3 Code Table :
| Decimal | Decimal + 3 | Excess-3 Code |
|---|---|---|
| 0 | 3 | 0011 |
| 1 | 4 | 0100 |
| 2 | 5 | 0101 |
| 3 | 6 | 0110 |
| 4 | 7 | 0111 |
| 5 | 8 | 1000 |
| 6 | 9 | 1001 |
| 7 | 10 | 1010 |
| 8 | 11 | 1011 |
| 9 | 12 | 1100 |
Examples
Section titled “Examples”Example 1: Decimal 2
2 + 3 = 5Binary(5) = 0101Excess-3 Code:
0101Example 2: Decimal 7
7 + 3 = 10Binary(10) = 1010Excess-3 Code:
1010Example 3: Decimal Number 59
Separate each decimal digit: ⭐
5 → 5 + 3 = 8 → 10009 → 9 + 3 = 12 → 1100So:
59 = 1000 1100 (XS-3)Properties of Excess-3 Code
Section titled “Properties of Excess-3 Code”1. Non-Weighted Code
There are no fixed positional weights like:
8, 4, 2, 1So 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 = 01011’s complement = 10101010 = XS-3 of 7Since:
9 − 2 = 7Hence XS-3 is self-complementary.
3. Uses 4 Bits
Each decimal digit is represented using 4 bits.
Why Excess-3 Code is Used
Section titled “Why Excess-3 Code is Used”-
Simplifies Decimal Subtraction Due to self-complementary property, subtraction becomes easier.
-
Used in Decimal Arithmetic Useful in:
- Adders
- Subtractors
- Digital arithmetic circuits
-
Reduces Transition Errors Some invalid combinations help identify errors in circuits.
-
Useful in Digital Electronics Used in:
- Digital systems
- Calculators
- Arithmetic logic circuits
Difference Between BCD and Excess-3
Section titled “Difference Between BCD and Excess-3”| Feature | BCD | Excess-3 |
|---|---|---|
| Type | Weighted | Non-weighted |
| Representation | Actual binary | Binary after adding 3 |
| Decimal 0 | 0000 | 0011 |
| Decimal 5 | 0101 | 1000 |
| Self-Complementary | No | Yes |