Binary codes or digital codes– In the digital logic circuits, each decimal or piece of information is represented through an equivalent combination of binary digits.
Binary codes can be classified into two types.
- Weighted codes – Positional Weights (positively weighted codes and negatively weighted codes)
- Unweighted codes
Example:
- 8421 code
- 2421 code
- 84-2-1 code
- Excess 3 Code
- Gray Code
Binary Codes for Decimal digits
The following table shows the various binary codes for decimal digits 0 to 9.
Decimal Digit | 8421 Code | 2421 Code (0-4) Normal Binary Code (5-9) 2421 codes | 84-2-1 Code | Excess 3 Code |
---|---|---|---|---|
0 | 0000 | 0000 | 0000 | 0011 |
1 | 0001 | 0001 | 0111 | 0100 |
2 | 0010 | 0010 | 0110 | 0101 |
3 | 0011 | 0011 | 0101 | 0110 |
4 | 0100 | 0100 | 0100 | 0111 |
5 | 0101 | 1011 | 1011 | 1000 |
6 | 0110 | 1100 | 1010 | 1001 |
7 | 0111 | 1101 | 1001 | 1010 |
8 | 1000 | 1110 | 1000 | 1011 |
9 | 1001 | 1111 | 1111 | 1100 |
We have 10 digits in decimal number system. To represent these 10 digits in binary, we require minimum of 4 bits. But, with 4 bits there will be 16 unique combinations of zeros and ones. Since, we have only 10 decimal digits, the other 6 combinations of zeros and ones are not required.
1) 8421 Code
- Its weights are 8, 4, 2 and 1.
- It has all +ve weights. So, it is a positively weighted code.
- Also called as natural BCD BinaryCodedDecimal code.
Example
Let us find the BCD equivalent of the decimal number 372. This number has 3 decimal digits 3, 7 and 2. From the table, we can write the BCD 8421 codes of 3,7 and 2 are 0011, 0111 and 0010 respectively.
∴ 37210 = (0011 0111 0010)BCD
There are 12 bits in BCD representation, since each BCD code of decimal digit has 4 bits.
2) 2421 Code
- Its weights are 2, 4, 2 and 1.
- It has all positive weights. So, it is a positively weighted code.
- It is an unnatural BCD code. Sum of weights of unnatural BCD codes is equal to 9.
- It is a self-complementing code or Reflective Code. Self-complementing codes provide the 9’s complement of a decimal number, just by interchanging 1’s and 0’s in its equivalent 2421 representation.
Example 1: Convert Binary of 5 into 2421 code
Solution:
- 2421 or (2+4+2+1) have to sequence
- Value is 5 so we take (2+2+1) only & ignore 4 as it
- 2+2+1=5 became and Wherever these 3 positions, write 1, the rest is 0.
- So 2421 = 1011
Example 2: Convert 7 of 8421 into 2421 code
Solution:
8421 values same as binary values
- Convert in 2+4+2+1 & make its sum as 7
- So we can take 2+4+1 = 7
- So 2421 = 1101
Example 3: Convert 372 into 2421 code
Solution:
3 -> 0011
7 -> 1101 (2+4+2+1 => (2+4+1) =7 so replace the value as 1 (1101))
2 -> 0010
So equivalent of the decimal number 372 = 0011 1101 0010
3) 8 4 -2 -1 Code
- Its weights are 8, 4, -2 and -1.
- It has negative weights along with positive weights. So, it is a negatively weighted code.
- It is an unnatural BCD code.
- It is a self-complementing code.
Example 1: Convert 6 into 8 4 -2 -1 code
Solution:
Same as previous rule
Value needed = 6 = ( 8-2)
So 8 -2 is taken as ‘1’ & others ‘0’
ie. 8 4 -2 -1 = 1010
Example 2: Convert 862 into 8 4 -2 -1 code
Solution
8 => 1000 (8 4 -2 -1 => replace 8 position as ‘1’ others ‘0’)
6 => 1010 (8 4 -2 -1 => (8-2 = 6) => replace 8 and -2 position as ‘1’ and others ‘0’
2 => 0110 (8 4 -2 -1 => (4-2=2) => replace 4 and -2 position as ‘1’ and others ‘0’
Value of 862 = 1000 1010 0110
4) Excess 3 Code
- It doesn’t have any weights. So, it is an un-weighted code.
- Binary value of 3 – 0011
- Add value of 3 with all
- It is a self-complementing code.
Example 1: Find access-3 value of 5?
Solution:
5 = 0101
3 = 0011
So, 5+3 => 0101+0011 => 1000
Example 1: Find access-3 value of 9?
Solution:
9 = 1001
3 = 0011
So 9+3 => 1001 + 0011 = 1100
5) Gray Code
- It doesn’t have any weights. So, it is an un-weighted code.
- In the below table, the successive Gray codes are differed in one bit position only. Hence, this code is called as unit distance code.
- A Gray code is an encoding of numbers so that adjacent numbers have a single digit differing by 1. The term Gray code is often used to refer to a “reflected” code, or more specifically still, the binary reflected Gray code.
The following table shows the 4-bit Gray codes corresponding to each 4-bit binary code.
Decimal Number | Binary Code | 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 |
Binary code to Gray Code Conversion
Follow these steps for converting a binary code into its equivalent Gray code.
- Consider the given binary code and place a zero to the left of MSB.
- Compare the successive two bits starting from zero. If the 2 bits are same, then the output is zero. Otherwise, output is one.
- Repeat the above step till the LSB of Gray code is obtained.
Example
From the table, we know that the Gray code corresponding to binary code 1000 is 1100. Now, let us verify it by using the above procedure.
Given, binary code is 1000.
Step 1 − By placing zero to the left of MSB, the binary code will be 01000.
Step 2 − By comparing successive two bits of new binary code, we will get the gray code as 1100.
#2421 code #8 4 -2 -1 #8421 code #Digital Circuit #Digital Circuit Codes #Excess 3 code #gray code #self complement
This article provides more insights. Also useful for students and faculties whoever preparing UGC Net exam. Thanks