In this tutorial, you will learn the basics of Excess-3 and Gray codes, including their definitions, conversion methods, advantages, and disadvantages. You will explore their applications in digital systems and understand the differences between Gray and Baudot codes, as well as the distinctions between Excess-3 and ASCII codes. This overview will provide insights into the functionalities and uses of these coding systems in computing.

**Contents:**

- What is Excess-3 Code?
- Decimal to Excess-3 Conversion
- Excess-3 to Decimal Conversion
- Advantages of Excess-3 Code
- Disadvantages of Excess-3 Code
- What is Gray Code?
- Binary to Gray Code Conversion
- Gray Code to Binary Conversion
- Advantages and Disadvantages of Gray Code
- Applications of Gray and Excess-3 Codes
- Differences Between Gray and Baudot Code
- Differences Between Excess-3 Code and ASCII Code
- Differences Between Gray and Excess-3 Code

## What is Excess-3 Code?

Excess-3 code is an unweighted, self-complementary code that is used to overcome the shortcomings found in BCD codes. Excess-3 like BCD is also used to represent decimal numbers and is a 4-bit encoded form of it in terms of 0s and 1s.

For each decimal digit, the excess-3 code is obtained by adding three (0 0 1 1) to its corresponding BCD code or it can also be obtained by adding 3 to its decimal digit and then writing the equivalent binary number for it.

The following table shows the excess-3 code for decimal digits.

Decimal Numbers | BCD | Excess-3 code |
---|---|---|

0 | 0000 | 0011 |

1 | 0001 | 0100 |

2 | 0010 | 0101 |

3 | 0011 | 0110 |

4 | 0100 | 0111 |

5 | 0101 | 1000 |

6 | 0110 | 1001 |

7 | 0111 | 1010 |

8 | 1000 | 1011 |

9 | 1001 | 1100 |

As shown in the table, each excess-3 code is obtained by adding 3 to its BCD code.

## Decimal to Excess-3 Conversion

To convert a decimal number into excess-3, we write down the equivalent excess-3 codes for each decimal digit separately. To get the excess-3 codes for each digit,

- We add 3 to each decimal digit individually, the maximum sum that can occur this way is 9 +3 = 12.
- We then write down the binary values in 4-bits for each obtained digit.
- Alternatively, we can add 0011 to the BCD codes for each decimal digit directly.

For example,

- (67.43)
_{10}in excess-3 is given as: –

67.43 + 33.33 = (9) (10) . (7) (3) (Add 3 individually to each digit)

= (1001 1010. 0111 0011) (Each digit’s corresponding binary value is written) - (1542) in excess-3 is given as: –

1542 + 3333 = (4) (8) (7) (5) (Add 3 individually to each digit)

= (0100 1000 0111 0101) (Each digit’s corresponding binary value is written)

## Excess-3 to Decimal Conversion

To convert a decimal number into excess-3, we will follow reverse steps of what we did previously. The steps are:

- Make groups of 4-bits beginning from the LSB.
- Subtract 0011 from each group of 4-bits, and write down its equivalent decimal value.
- For conversion into decimal, the groups must lie between (0011-1100) as only these are valid Excess-3 groups that have decimal single-digit representations.
- For example, if we had 1111 as the group, subtracting 0011 from it, it becomes 1100 which is 12 in decimal and is not a single digit.

Examples of Excess-3 to decimal conversion are,

- (1011 1000) in decimal is given as: –

(1011 – 0011) (1000 – 0011) = (1000) (0101) (Subtracting 0011 from each group)

= (85)_{10} - (1010 1100) in decimal is given as: –

(1010 – 0011) (1100 – 0011) = (0111) (1001) (Subtracting 0011 from each group)

= (79)_{10}

## Advantages of Excess-3 Code

The advantages of Excess-3 code include:

- It is self-complementary, meaning the 9’s complement of decimal digits corresponds to their respective Excess-3 codes as 1’s complements. For example, the 9’s complement of 0 (which is 9) has an Excess-3 code of 0011. Inverting all digits results in 1100, which is the Excess-3 code for 9.
- It simplifies overflow detection, which is not possible with Binary-Coded Decimal (BCD) codes.
- It retains a sequential nature like BCD, allowing for easier processing.
- Bits in the Excess-3 coding system are faster and easier to operate on compared to a pure binary system.
- It is self-complementing, so performing a 1’s complement operation on any Gray number yields another Gray number.

## Disadvantages of Excess-3 Code

The disadvantages of Excess-3 code are:

- It requires four bits to represent a decimal number, while a pure binary system can represent the same decimal number with fewer bits, making Excess-3 less efficient.
- Performing arithmetic operations with Excess-3 numbers is more complex, requiring separate techniques and algorithms.
- Only ten 4-bit combinations are used out of a possible 16, leading to a higher frequency of errors.

## What is Gray Code?

Gray Code is also an unweighted code. Gray Code is obtained from the binary form of decimal digits. It is known as a unit distance code as between the gray codes of any two successive binary numbers only one-bit changes. Here is a table that shows the gray codes for digits from 0-15.

Binary’s decimal value | Binary Number | Gray Code |
---|---|---|

0 | 0000 | 0000 |

1 | 0001 | 0001 |

2 | 0010 | 0011 |

3 | 0011 | 0010 |

4 | 0100 | 0110 |

5 | 0101 | 0111 |

6 | 0110 | 0101 |

7 | 0111 | 0100 |

8 | 1000 | 1100 |

9 | 1001 | 1101 |

10 | 1010 | 1111 |

11 | 1011 | 1110 |

12 | 1100 | 1010 |

13 | 1101 | 1011 |

14 | 1110 | 1001 |

15 | 1111 | 1000 |

As shown in the table,

- Between any two successive gray codes, only one-bit changes. It also can be noted that gray code is non-sequential, as the next decimal digit’s gray code cannot be obtained by adding 1 to its previous gray code.

## Binary to Gray Code Conversion

The gray code for a number can be obtained from its binary number using the following steps: –

- Write down the binary form of the number.
- The first digit (MSB) of binary is copied as the first digit of gray code.
- The next bits can be obtained by performing XOR operations between the neighbouring binary digits going from MSB to LSB.
- This is done till we perform XOR operation between the two last binary digits.

Here are some examples shown in the figure.

As shown in the figure,

- (1011) in gray code is written as: –
- The first digit 1 is copied as it is.
- The next gray digit is (1 XOR 0) as 1 is the MSB of binary and 0 is its right neighbouring bit. Thus,

1 XOR 0 = 1 - The next digit is (0 XOR 1) = 1
- The next is, 1 XOR 1 = 0
- Thus, the obtained gray code is 1110.
- (1100) in gray code is written as: –
- The first digit 1 is copied as it is.
- The next gray digit is (1 XOR 1) as 1 is the MSB of binary and 1 is its right neighbouring bit. Thus,

1 XOR 1 = 0 - The next digit is (1 XOR 0) = 1
- The next is, 0 XOR 0 = 0
- Thus, the obtained gray code is 1010
- All the arrows shown in red denote XOR operation in the right direction between binary digits.

## Gray Code to Binary Conversion

The binary code can be obtained from gray code by using XOR operations in the reverse direction. The steps to follow for converting a gray number into binary are: –

- Write the MSB of gray code as the MSB of the binary number directly.
- The next digits of the binary number are obtained by performing XOR operations with the obtained binary digit and the next gray digit right to the MSB.
- The process is repeated to its right till the last gray digit is XORed with.

The following figure shows the examples of gray to binary conversion.

As shown in the figure,

- Gray code of (1110) in binary is given as: –
- The MSB is copied as it is. MSB = 1
- Then we XOR this obtained binary digit with the next gray digit.

(1 XOR1) = 0 - The next digit is, (0 XOR 1) =1
- And the LSB is (1 XOR 0) =1
- Thus, obtained binary number is 1011
- Gray code of (1100) in binary is given as: –
- The MSB is copied as it is. MSB = 1
- Then we XOR this obtained binary digit with the next gray digit.

(1 XOR1) = 0 - The next digit is, (0 XOR 0) =0
- And the LSB is (0 XOR 0) =0
- Thus, obtained binary number is 1000
- The red arrow shows the direction of the XOR operation performed.

## Advantages and Disadvantages of Gray Code

**Advantages of Gray Code:**

- This coding system uses only XOR logic operation which makes it very simple to understand and operate.
- For consecutive numbers only one bit change occurs. So, this is very helpful to avoid unwanted switching transients and glitches in circuits.
- As compared to BCD and binary codes, gray codes can be read steadily to match the reading timings for input and output devices because when the code changes it changes only by 1 bit.
- Switching system for this coding system is very much reliable and minimized as at each step to change numbers only one bit change is required.
- It is widely used in digital communication for error correction and detection techniques.
- For naming the cells of K-Map gray coding system is used. K-Map is one of the most important part of digital circuits to obtain POS and SOP.

**Disadvantages of Gray Code:**

- It is not suitable for arithmetic operations. So, this can’t be used for Arithmetic Logic Unit (ALU) operations inside microprocessors.

## Applications of Gray and Excess-3 Codes

The applications of gray and excess-3 codes are:

- Gray codes are used to name the cells in K-maps where two consecutive cells differ by 1 bit. It helps grouping of minterms or maxterms to produce a minimized Boolean expression.
- Gray codes are used to control false outputs from electromechanical switches. They are also used in digital communication to detect errors.
- Excess-3 codes are self-complementing codes, their arithmetic operations are much simpler than BCD. So, they are preferred over BCD arithmetic operations.

## Differences Between Gray and Baudot Code

The differences between Gray and Baudot code are listed below.

Parameters | Gray code | Baudot code |
---|---|---|

Classification | It is a binary classification of codes. | It is an alphanumeric classification of codes. |

Symbols | It uses binary bits for coding. | It uses dots and crosses for coding. |

Origin | This coding technique was introduced by Frank Gray in 1947. | It was introduced by Emile Baudot in 1870. |

Simplicity & Difficulty |
Two consecutive codes differ by 1 bit so they are very easy to remember. | These are very long and complex codes. So, they are very difficult to remember. |

Common Uses | It is commonly used to detect errors in digital communication. | It is commonly used in telegraphic systems. |

## Differences Between Excess-3 Code and ASCII Code

The differences between excess-3 code and ASCII code are listed below.

Parameters | Excess-3 Code | ASCII code |
---|---|---|

Classifications | It is a binary coding system. | It is an alphanumeric coding system. |

Symbols | It uses ten decimal digits in 4-bit binary form. | It uses 128 characters including alphabets and digits. |

Origin | It was developed from Binary Coded Decimal by adding 0011 to each 4-bit BCD number to make it a self-complementing code. | ASCII stands for American Standard-Code for Information Interchange. It was published in 1967. |

Application in computers | It doesn’t have any application in computers as it uses only ten decimal digits. | It is commonly used in computer systems to uniquely represent alphanumeric data. |

Examples | Excess-3 representation of decimal number 7 is 1010. | ‘a’ in ASCII code is represented by the number 97. |

## Differences Between Gray and Excess-3 Code

The differences between gray code and excess-3 code are listed below:

Parameters | Gray Code | Excess-3 Code |
---|---|---|

No. of bits | It can be of any number of bits. | It is a 4-bit code. |

Generation | This code is generated from binary codes with the help of XOR operations. | It can be developed from BCD by adding 0011 to each BCD number. |

Self-Complementing code | It is not a self-complementing coding system. | It is a self-complementing coding system. |

Uses | It is commonly used to name the cells in K-maps and for inputs and outputs in electronic devices. | Due to self-complementing property it is commonly used in arithmetic circuits. |

Bit Change | Consecutive numbers have only one bit change. | Consecutive numbers can have any number of changes in bit. |

Examples | Gray code of decimal number 9 is 1101. | Excess-3 code of decimal number 9 is 1100. |

## Key Points to Remember

Here are the key points to remember in “Excess-3 and Gray Code”.

- Excess-3 and gray codes are unweighted codes as they do not depend on positional values.
- Excess-3 codes for decimal number is obtained by adding 0011 to its BCD codes or by adding 3 to its decimal value and then writing its binary form.
- Excess-3 code is more used than BCD as they become self-complementary but remain sequential like BCD codes.
- Gray code is a unit distance code because between any of its two successive codes, only one-digit changes.
- Gray codes are obtained from binary numbers by performing XOR operation between two neighbouring binary digits starting from MSB to LSB.
- For converting from binary to Gray Code, the first bit is copied, and subsequent bits are determined using XOR operations; for Gray Code to binary, the first bit is copied, and the rest are found through XOR with previous binary values.
- Gray codes are used in K-maps and error detection in digital communication, while Excess-3 codes facilitate simpler arithmetic operations.
- Gray Code differs from Baudot Code in complexity and application; Excess-3 Code is distinct from ASCII Code, focusing solely on decimal representation, while ASCII covers a wider range of alphanumeric characters.