Digital Design – Binary-Coded Decimal

In the previous lesson, we learned about binary codes and how they are used for representing a distinct discrete element of information using 1s and 0s.

Binary Coded Decimal Overview

People use decimal system for everything and it’s easier for them to use decimal numbers on computer than binary numbers. But binary is what computer understands.

So we need a system to convert decimal to binary and perform calculation using binary numbers and convert the output back to decimal for users.

This binary representation of decimal number is called the binary coded decimal code or BCD code.

Binary-Coded Decimal (BCD code)

The binary coded decimal is a 4-bit code and each 4-bit code is represents one decimal digit from 0 to 9. See the table below

Decimal Digit Binary Coded Decimal
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001

But there are 16 codes because 24 = 16 combinations. The codes from 1010 to 1111 does not matter and are not used in BCD.

For example

The binary and BCD value of 128 is given below for your understanding.

Binary number for 12810 BCD Code for 12810
1000 00000001 0010 1000

Important points to remember

  1. Decimal number is 0, 1, 2, 3, so on, and BCD code is 0000, 0001, 0011… It means they are same.
  2. Binary number is not BCD, there is a difference.
  3. BCD coded decimal numbers need more bits. See the example above.

BCD Addition

When two BCD numbers are added then two things happens

  1. Sum is less than 1010 = decimal 10
  2. Sum is equal to or more than decimal 10

Suppose you add following BCD numbers

[cc lang=”c” tab_size=”4″ line_numbers=”off”]
4 + 3

0 1 0 0
0 0 1 1
________
0 1 1 1 = 7
[/cc]

The result is a BCD sum and less than 1010.

First Case – when BCD sum does not have a carry

Consider another example

[cc lang=”c” tab_size=”4″ line_numbers=”off”]
8 + 4

1 0 0 0
0 1 0 0
________
1 1 0 0 = 12
[/cc]

The BCD does not allow 1100 and we need 12 as answer in BCD. The first digit is 1 and second digit is 2.There are 16 codes in BCD and we are using only 10 of them.

[cc lang=”c” tab_size=”4″ line_numbers=”off”]
1010 + 0110 = 1 carry + 0000 = 0001 0000 = 10 in BCD

1011 + 0110 = 1 carry + 0001 = 0001 0001 = 11 in BCD

1100 + 0110 = 1 carry + 0010 = 0001 0010 = 12 in BCD

1101 + 0110 = 1 carry + 0011 = 0001 0011 = 13 in BCD

1110 + 0110 = 1 carry + 0100 = 0001 0100 = 14 in BCD

1111 + 0110 = 1 carry + 1000 = 0001 0101 = 15 in BCD
[/cc]

Then whenever, you get an invalid BCD sum, add a 0110 = 6 to the result and you will get the correct BCD sum.

Second Case – when BCD sum has a carry

We not look at another case of BCD sum when the result appears to be correct but it has a carry.

[cc lang=”c” tab_size=”4″ line_numbers=”off”]
8 + 9

1 0 0 0

+1 0 0 1
__________
1 0 0 0 1
[/cc]

In this case, we still add 0110 = 6 to the 4 least significant bits.

[cc lang=”c” tab_size=”4″ line_numbers=”off”]
1 0 0 0 1

0 1 1 0
__________
1 0 1 1 1 = 1 carry + 0111 = 0001 0111 = 17
[/cc]

Example – BCD Addition

In this example, we will add two decimal numbers,

[cc lang=”c” tab_size=”4″ line_numbers=”off”]
214 + 389 = 603

0 0 1 0 0 0 0 1 0 1 0 0 = 214

+0 0 1 1   1 0 0 0   1 0 0 1 = 389
____________________________________
0 1 1 0   1 0 1 0   1 1 0 1
0 1 1 0   0 1 1 0
____________________________________
0 1 1 0   0 0 0 0   0 0 1 1 = 603
[/cc]


Bibliography

John.F.Wakerly. 2008. Digital Design: Principles And Practices, 4/E. Pearson Education, India.

Mano, M. Morris. 1984. Digital Design. Pearson.

 

 

Advertisements