Codes 1
Codes 1
(DIGITAL ELECTRONICS)
2nd Semester AY 2024-2025
Binary Coded Decimal (BCD) - is a type of binary code used to represent a given decimal number in an equivalent binary
form.
The BCD equivalent of a decimal number is written by replacing each decimal digit in the integer and fractional parts with its
four-bit binary equivalent.
The BCD code described above is more precisely known as the 8421 BCD code, with 8, 4, 2 and 1 representing the weights
of different bits in the four-bit groups, starting from MSB and proceeding towards LSB. This feature makes it a weighted code,
which means that each bit in the four-bit group representing a given decimal digit has an assigned weight.
Other weighted BCD codes include the 4221 BCD and 5421 BCD codes. Again, 4, 2, 2 and 1 in the 4221 BCD code and 5, 4,
2 and 1 in the 5421 BCD code represent weights of the relevant bits.
Table 2.1 shows a comparison of 8421, 4221 and 5421 BCD codes. As an example, (98.16)10 will be written as 1111
1110.0001 1100 in 4221 BCD code and 1100 1011.0001 1001 in 5421 BCD code. Since the 8421 code is the most popular of
all the BCD codes, it is simply referred to as the BCD code
Table 2.1 BCD Codes
Decimal 8421 BCD code 4221 BCD code 5421 BCD code
0 0000 0000 0000
1 0001 0001 0001
2 0010 0010 0010
3 0011 0011 0011
4 0100 1000 0100
5 0101 0111 1000
6 0110 1100 1001
7 0111 1101 1010
8 1000 1110 1011
9 1001 1111 1100
2.1.1 BCD-to-Binary Conversion
A given BCD number can be converted into an equivalent binary number by first writing its decimal equivalent and
then converting it into its binary equivalent. As an example, we will find the binary equivalent of the BCD number
0010 1001.0111 0101:
The process of binary-to-BCD conversion is the same as the process of BCD-to-binary conversion executed in reverse order.
A given binary number can be converted into an equivalent BCD number by first determining its decimal equivalent and then
writing the corresponding BCD equivalent. As an example, we will find the BCD equivalent of the binary number
10101011.101:
10101011 = (1×27 ) + (0×26 ) + (1×25 ) + (0×24 ) + (1×23 ) + (0×22 )+ (1×21 ) + (1×20 )
= 128 + 0 + 32 + 0 + 8 + 0 + 2 + 1
= 171
0 .101 = (1×2−1 )+ (0×2−2 )+ (1×2−3 )
= (1 × ½) + (0 × ¼) + (1 × 𝟏 𝟖)
= 0.5 + 0 + 0.025
= 0.625
Note: if it is negative make it positive by inverting the bits and adding one.
Example: let us find the excess-3 code for the decimal number 597:
• The addition of ‘3’ to each digit yields the three new digits/numbers ‘8’,
‘12’ and ‘10’.
• The corresponding four-bit binary equivalents are 1000, 1100 and 1010
respectively.
• The excess-3 code for 597 is therefore given by:
1000 1100 1010 = 100011001010