Advertisement

Binary Coded Decimal

Binary Coded Decimal

Binary Coded Decimal, or BCD, is another process for converting decimal numbers into their binary equivalents using just 4 bits

What is a Binary Coded Decimal Number?

Binary Coded Decimal (BCD) is another type of binary encoding used in digital and electronic circuits. Unlike the standard binary numbering system, which converts the entire number, BCD converts each digit individually, making it ideal for 7-segment displays and input keyboards.

As we have seen in this Binary Numbers section of tutorials, there are many different types of encoding systems each with its own specific use. BCD encodes each decimal digit (0-9) of a binary number into a 4-bit binary sequence ranging from 0000 to 1001 (0 to 9).

As we naturally live in a decimal (base-10) world were decimal numbers are “native” for humans, and binary numbers are “native” for computers We need some way of converting these decimal numbers into a binary (base-2) number that computers and digital electronic devices can understand.

Then as a stand-alone numeral system, the binary coded decimal (BCD) format allows us to do that since we can use just one byte for each decimal digit. Thus each byte holds the digit’s binary code.

Creating an n-bit Code

We have seen previously that an n-bit binary code is a group of “n” bits that assume up to 2n distinct combinations of 1’s and 0’s. The advantage of the Binary Coded Decimal system is that each decimal digit is represented by a group of 4 binary digits or bits in much the same way as Hexadecimal Numbers. So for the 10 decimal digits (0-to-9) we need a 4-bit binary code.

But do not get confused, binary coded decimal is not the same as hexadecimal. Whereas a 4-bit hexadecimal number is valid up to F16 representing binary 11112, (decimal 15), binary coded decimal numbers stop at 9 binary 10012.

This means that although 16 numbers (24) can be represented using four binary digits, in the BCD numbering system the six binary code combinations of: 1010 (decimal 10), 1011 (decimal 11), 1100 (decimal 12), 1101(decimal 13), 1110 (decimal 14), and 1111 (decimal 15) are classed as forbidden numbers and can not be used.

Advantage of Binary Coded Decimal

The main advantage of binary coded decimal is that it allows for easy conversion of numbers producing a direct human-readable output between decimal (base-10) and binary (base-2) form. Also, BCD represents each decimal digit independently using 4 bits (0000 to 1001), it eliminates any rounding errors that can occur with binary conversion.

While a BCD Counter Circuit counts upwards from 0 to 9 on the application of an external clock signal creating a divide-by-10 counting sequence.

However, the disadvantage is that BCD code is wasteful as the states between 1010 (decimal 10), and 1111 (decimal 15) are not used. Nevertheless, binary coded decimal has many important applications especially using digital Display Decoders.

In the BCD numbering system, a decimal number is separated into four bits for each decimal digit within the number. Each decimal digit is represented by its weighted binary value performing a direct translation of the number.

Decimal to BCD Conversion

Thus a 4-bit group of BCD bits represents each displayed decimal digit from 0000 for a zero (0), to 1001 for a nine (9). For example: 35710 (Three Hundred and Fifty Seven) in decimal would be presented in binary coded decimal (BCD) as:

35710 = 0011 0101 0111 (BCD)

Then we can see that BCD code uses weighted codification. That is each bit position is assigned a specific weight because the binary bit of each 4-bit group represents a given weight of the final value.

In other words, the BCD is a weighted code and the weights used in binary coded decimal code are 8, 4, 2, 1, commonly called the 8421 code. This because it forms the 4-bit binary representation of the relevant decimal digit.

Binary Coded Decimal Representation of a Decimal Number

Binary Power23222120
Binary Weight:8421

The decimal weight of each decimal digit to the left increases by a factor of 10. In the BCD number system, the binary weight of each digit increases by a factor of 2 as shown.

Then the first digit has a weight of: 1 (20), the second digit has a weight of: 2 (21), the third a weight of: 4 (22), the fourth a weight of: 8 (23).

Then the relationship between decimal (denary) numbers and weighted binary coded decimal digits is given below.

Truth Table for Binary Coded Decimal

Decimal NumberBCD 8421 Code
00000 0000
10000 0001
20000 0010
30000 0011
40000 0100
50000 0101
60000 0110
70000 0111
80000 1000
90000 1001
10 (1 + 0)0001 0000
11 (1 + 1)0001 0001
12 (1 + 2)0001 0010
20 (2 + 0)0010 0000
21 (2 + 1)0010 0001
22 (2 + 2)0010 0010
etc, continuing upwards in groups of four

Then we can see that 8421 BCD code is nothing more than the weights of each binary digit, with each decimal (denary) number expressed as its four-bit pure binary equivalent.

Decimal to 8421 BCD Conversion

As we have seen above, the conversion of decimal to binary coded decimal is very similar to the conversion of hexadecimal to binary. Firstly, separate the decimal number into its weighted digits and then write down the equivalent 4-bit 8421 BCD code representing each decimal digit as shown.

Binary Coded Decimal Worked Example No1

Using the above table, convert the following decimal (denary) numbers: 8510, 57210 and 857910 into their 8421 BCD equivalents.

8510 = 1000 0101 (BCD)

57210 = 0101 0111 0010 (BCD)

857910 = 1000 0101 0111 1001 (BCD)

Note that the resulting binary number after the conversion will be a true binary translation of decimal digits. This is because the binary code translates as a true binary count.

BCD-to-Decimal Conversion

The conversion from binary coded decimal to decimal is the exact opposite of the above. Simply divide the binary number into groups of four digits, starting with the least significant digit and then write the decimal digit represented by each 4-bit group.

Add additional zero’s at the end if required to produce a complete 4-bit grouping. So for example, 1101012 would become: 0011 01012 or 3510 in decimal.

Binary Coded Decimal Worked Example No2

Convert the following binary numbers: 10012, 10102, 10001112 and 10100111000.1012 into their decimal equivalents.

10012 = 1001BCD = 910

10102 (this will produce an error as it’s decimal 1010 and not a valid BCD number)

10001112 = 0100 0111BCD = 4710

10100111000.1012 = 0101 0011 0001.1010BCD = 538.62510

Then we can see that the conversion of BCD-to-decimal or decimal-to-BCD is a relatively straight forward task. But we need to remember that BCD numbers are decimal numbers and not binary numbers, even though they are represented using individual bits.

The Fundamentals of BCD

The BCD representation of a decimal number is important to understand, because microprocessor based systems used by most people needs to be in the decimal system.

However, while BCD is easy to code and decode, it is not an efficient way to store numbers. In the standard 8421 BCD encoding of decimal numbers, the number of individual data bits needed to represent a given decimal number will always be greater than the number of bits required for an equivalent binary encoding.

For example, in binary a three digit decimal number from 0-to-999 requires only 10-bits (11111001112), whereas in binary coded decimal, the same number requires a minimum of 12-bits (0011 1110 0111BCD) for the same representation.

Also, performing arithmetic tasks using binary coded decimal numbers can be a bit awkward since each digit can not exceed 9. The addition of two decimal digits in BCD, will create a possible carry bit of 1 which needs to be added to the next group of 4-bits.

If the binary sum with the added carry bit is equal to or less than 9 (1001), the corresponding BCD digit is correct. But when the binary sum is greater than 9 the result is an invalid BCD digit. Therefore it is better to convert BCD numbers into pure binary, perform the required addition, and then convert the back to BCD before displaying the results.

BCD For Driving Output Displays

Nevertheless, the use of a BCD coding system in both microelectronics and computer systems is particularly useful in situations where the binary coded decimal is intended to be displayed on one or more 7-segment LED or LCD displays and there are many popular integrated circuits available that are configured to give a BCD output or outputs.

One common IC is the 74LS90 Asynchronous Counter and divider that contains independent divide-by-2 and divide-by-5 counters which can be used together to produce a divide-by-10 decade counter with BCD outputs. Another is the 74LS390 which is a dual version of the basic 74LS90, and can also be configured to produce a BCD output.

But the most commonly used BCD encoded IC’s are the 74LS47 and the 74LS48 BCD to 7-segment decoder/driver chips. These convert a standard 4-bit BCD code from a counter into the required code to drive the individual segments of a 7-segment LED Display.

While both IC’s are functionally the same, the 74LS47 has active-low outputs for driving common-anode displays, while the 74LS48 has active-high outputs for driving common-cathode displays.

Binary Coded Decimal Decoder IC

binary coded decimal display

Binary Coded Decimal Summary

We have seen here that Binary Coded Decimal or BCD is simply the 4-bit binary code representation of a decimal number. Each decimal digit replaced in the integer and fractional parts with its binary equivalent. BCD Code uses four bits to represent the 10 decimal digits of 0 to 9.

For example, to display decimal numbers in the range of 0 to 9, (one digit) we would need 4 data bits (a nibble). So for 2-digit decimal numbers in the range of 0 to 99, then we would need 8 bits (one byte). A decimal number in the range of 0 to 999, (three digits) we would require 12 bits, and so on.

The use of a single byte (8-bits) to store or display two BCD digits, allowing a byte to hold a BCD number in the range of 00 – 99, is known as packed BCD.

Standard binary coded decimal code is commonly known as a weighted 8421 BCD code, with 8, 4, 2 and 1 representing the weights of the different bits starting from the most significant bit (MSB) and proceeding towards the least significant bit (LSB).

Thus the weighted representation value of a 8421 BCD Code is calculated by multiplying the individual bits by their weights: 23 = 8, 22 = 4, 21 = 2, 20 = 1.

Decimal to Weighted 8421 Binary Coded Decimal

Image

The main advantage of the Binary Coded Decimal system is that it is a fast and efficient system to convert the decimal numbers into binary numbers as compared to the pure binary system. But the BCD code is wasteful as many of the 4-bit states (10-to-16) are not used.

This because with 4 bits, we can represent sixteen numbers (0000 to 1111) in binary. However, in the BCD code only the first ten are used (0000 to 1001). The remaining six code combinations, i.e., 1010 to 1111 (A to F in Hex) are invalid in the binary coded decimal numbering format.

168 Comments

Join the conversation

Error! Please fill all fields.