#### Question: Q6.Discuss the following number system codes with at least two practical applications of each.

a. BCD

b. Gray codes

c. Excess- 3 codes

d. Sequential Codes

e. Error correction codes

f. Humming codes

g. Reflective codes

h. 2421 codes

i. 5211 codes

j. EBCDIC and ASCII codes

Q7. You are also required to solve at least two problems involving each of the codes in Q6. above.

**Answer:**

**1. BCD :** Each decimal digit is represented by a 4-bit binary number. BCD is a way to express each of the decimal digits with a binary code.

In the BCD, with four bits we can represent sixteen numbers (0000 to 1111). But in BCD code only first ten of these are used (0000 to 1001).

The remaining six code combinations i.e. 1010 to 1111 are invalid in BCD.

**Example :**

**357 _{10} = 0011 0101 0111 (BCD)**

**85 _{10} = 1000 0101 (BCD)**

**2. Gray Code :** It is the non-weighted code and it is not arithmetic codes. That means there are no specific weights assigned to the bit position.

The gray code is a cyclic code. Gray code cannot be used for arithmetic operation.

**Example :**

Decimal 7 |
Binary 111 |
Gray 100 |

Decimal 15 |
Binary 1111 |
Gray 1000 |

**3. Excess 3 :**

The Excess-3 code is also called as XS-3 code. It is non-weighted code used to express decimal numbers. The Excess-3 code words are derived from the 8421 BCD code words adding (0011)_{2} or (3)10 to each code word in 8421.

**Example**

**Decimal 9 -> Binary 1001 -> BCD + 0011 -> Excess 3 -> 1100**

**Decimal 7 -> Binary 0111 -> BCD + 0011 -> Excess 3 -> 1010**

**4. Sequential Code** :Sequential codes are the codes in which 2 subsequent numbers in binary representation differ by only one digit.

The 8421 and Excess-3 codes are examples of sequential codes.

Example :

**5. Error Correction Code** : error correcting code, is used for controlling errors in data over unreliable or noisy communication channels. In **error correcting code (ECC)** is an encoding scheme that transmits messages as binary numbers, in such a way that the message can be recovered even if some bits are erroneously flipped.

**For example, a message of “10101” might be transmitted as 111010111000110, where the bolded bits have been accidentally flipped.**

**5. Hamminh Code** : A more efficient encoding scheme is a **Hamming code.**

The Hamming distance between 2 numbers is the number of bits they differ at. For example, 1101010 and 1111000 are a hamming distance of 2 apart:

11**0**10**1**0

11**1**10**0**0

The key here is that if any pair of encodings are sufficiently far apart in terms of Hamming distance, errors can be detected and corrected by seeing which of the codewords is closest to the transmitted message.

**6. Reflective codes:** A code is reflective when the code is self complementing. In other words, when the code for 9 is the complement the code for 0, 8 for 1, 7 for 2, 6 for 3 and 5 for 4.

2421BCD, 5421BCD and Excess-3 code are reflective codes.

**Example : The code for 9 is 1111, whereas the code for 0 is 0000. Since 1111 and 0000 are complement of each other, the number 9 and 0 are said to be reflective codes.**

**7.2421 Code :** This is a weighted code, its weights are 2, 4, 2 and 1. A decimal number is represented in 4-bit form and the total four bits weight is 2 + 4 + 2 + 1 = 9. Hence the 2421 code represents the decimal numbers from 0 to 9.

Example : 1010 = 4 , 1100 = 6

**8 .5211 Code :** This is a weighted code, its weights are 5, 2, 1 and 1. A decimal number is represented in 4-bit form and the total four bits weight is 5 + 2 + 1 + 1 = 9. Hence the 5211 code represents the decimal numbers from 0 to 9.

Example : 1010 = 6 , 1100 =7

**9.ASCII Code :** ASCII is an acronym for American Standard Code for Information Interchange. It is a code that uses numbers to represent characters. Each letter is assigned a number between 0 and 127. …

For example the character **A is assigned the decimal number 65**, while a is assigned decimal 97 as shown below int the ASCII table.

The **EBCDIC** code allows for 256 different characters,Each byte consists of two nibbles, each four bits wide. The first four bits define the class of character, while the second nibble defines the specific character inside that class.