In one of the previous articles, we learned about Binary Coded Decimal (BCD) numbers. In this article, we will learn about how to convert a Decimal number to a BCD number and vice versa.
Decimal number to BCD number Conversion
To convert a decimal number to the BCD number, we need to replace every digit of the decimal number with its 4-bit unsigned binary equivalent.
Example: Convert the decimal number 9673 to BCD.
Solution:
967310 = (1001_0110_0111_0011)BCD
Example: Convert the decimal number 96.73 to BCD.
Solution:
96.7310 = (10010110.01110011)BCD
BCD number to Decimal number Conversion
To convert a BCD number to a decimal number, we need to start from the right and group the bits into 4 bits, and then replace every group of 4 bits with the equivalent decimal digit.
Example: Convert the BCD number 100001010111 to Decimal.
Solution:
(100001010111)BCD = 85710
Example: Convert the BCD number 011110101000 to Decimal.
Solution:
The given BCD number has one invalid code 1010, which is not a valid BCD number. So, the given number is not a valid BCD number, and therefore, we can not convert it to decimal.