CODING Binary code • Digital data is represented, stored and transmitted as group of binary bits. • This group is called binary code. • The binary code can be used for represent the number as well as alpha numeric letters. Classification of binary code Binary code Weighted code Binary Ex: 0s1 Non weighted code Reflective code Sequential code Error detecting and correcting code •Example: Gray Excess-3 Five bit BCD •Example: 5211 2421 Excess-3 •Example: 8421 Excess-3 •Example: Hamming Parity • BCD Ex: 8421 2421 5211 4221 Binary code decimal (BCD) • We know that decimal, octal, hexadecimal can be represented by binary digit. • Not only numbers but letters and other symbols can be represented by 1s 0s. • Combination of binary digits that represent all these things are called digital codes. Binary code decimal (BCD) 8421 (BCD) Decimal 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 Gray code • It is called cyclic or reflected code. • In this code each code group does not differ from its neighbour in more than one bit. • This code is used for input and output devices in digital system. Table of gray code Decimal number Gray code 0 0 0 0 0 1 0 0 0 1 2 0 0 1 1 3 0 0 1 0 4 0 1 1 0 5 0 1 1 1 6 0 1 0 1 7 0 1 0 0 8 1 1 0 0 9 1 1 0 1 10 1 1 1 1 11 1 1 1 0 12 1 0 1 0 Conversion from binary to gray code Method: • Write down binary form of the given decimal number. • Write MSB as such. • Then add the binary digit from left to right at the adjacent position. • Discard carry if any. • Write the digit which comes after addition. Conversion from binary to gray code • Example: Convert 15 into gray code. Solution: (15)10 = (1111)2 We have to convert (1111)2 into gray code Left most bit 1 1 + 1 0 + 1 0 + 1 0 Hence the resultant gray code is 1000 for 15. Example – Convert (111011)2 into gray code. Solution: Left most bit 1 1 1. 2. 3. + 1 0 + 1 0 + + + 0 1 1 1 1 0 Write the left most bit as such. Then add the binary digit from left to right at the adjacent position. Write the digit which comes after addition. Hence the grey code of (111011)2 is 100110. Conversion from grey code to binary code • Method: 1. Write the given grey code. 2. Write the left most bit as such. 3. Add this bit to the second left most bit, write the result, discard carry. 4. Add this result to the next left most bit diagonally. Conversion from grey code to binary code • Example: Convert the following grey code into binary code from (1 0 0 0). Solution: We have Left most bit 1 0 + 1 1 + 0 + 1 Hence the corresponding binary number us (1111)2. 0 1