How to Convert Decimal to BCD and BCD to Decimal

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:

Example of Decimal to BCD Conversion

967310 = (1001_0110_0111_0011)BCD

Example: Convert the decimal number 96.73 to BCD.

Solution:

Example of Fractional Decimal to BCD Conversion

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:

Example of BCD to Decimal conversion

(100001010111)BCD = 85710

Example: Convert the BCD number 011110101000 to Decimal.

Solution:

Example of invalid BCD number

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.

Previous           Table of Content           Next

Leave a Reply

Your email address will not be published. Required fields are marked *