# 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.

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

So we need a system to convert decimal to binary and perform the calculation using binary numbers and convert the output back to decimal for users. This binary representation of a 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 represents one decimal digit from 0 to 9. See the table below

But there are 16 codes because $2^4 = 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.

#### 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. The binary number is not BCD, there is a difference.
3. BCD coded decimal numbers need more bits. See the example above.

When two BCD numbers are added then two things happen

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

Suppose you add following BCD numbers

`````` $4 + 3$ $4 + 3$ $0100$ $0100$ $0011$ $0011$
------------- $0111 = 7_{10}$ $0111 = 7_{10}$``````

The result is a BCD sum and less than $1010$.

First Case – when BCD sum does not have a carry

Consider another example

`````` $8 + 4$ $8 + 4$ $1000$ $1000$ $0100$ $0100$
----------- $1100 = 12_{10}$ $1100 = 12_{10}$``````

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

``` $1010 + 0110 = 1$ $1010 + 0110 = 1$ carry $+ 0000$ $+ 0000$ = $0001 0000 = 10$ $0001 0000 = 10$ in BCD $1011 + 0110 = 1$ $1011 + 0110 = 1$ carry $+ 0001$ $+ 0001$ = $0001 0001 = 11$ $0001 0001 = 11$ in BCD $1100 + 0110 = 1$ $1100 + 0110 = 1$ carry $+ 0010$ $+ 0010$ = $0001 0010 = 12$ $0001 0010 = 12$ in BCD $1101 + 0110 = 1$ $1101 + 0110 = 1$ carry $+ 0011$ $+ 0011$ = $0001 0011 = 13$ $0001 0011 = 13$ in BCD $1110 + 0110 = 1$ $1110 + 0110 = 1$ carry $+ 0100$ $+ 0100$ = $0001 0100 = 14$ $0001 0100 = 14$ in BCD $1111 + 0110 = 1$ $1111 + 0110 = 1$ carry $+ 1000$ $+ 1000$ = $0001 0101 = 15$ $0001 0101 = 15$ in BCD```

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 now look at another case of BCD sum when the result appears to be correct but it has a carry.

`````` $8 + 9$ $8 + 9$ $1 0 0 0$ $1 0 0 0$ $+1 0 0 1$ $+1 0 0 1$
--------------- $1 0 0 0 1$ $1 0 0 0 1$``````

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

`````` $1 0 0 0 1$ $1 0 0 0 1$ $0 1 1 0$ $0 1 1 0$
----------------- $1 0 1 1 1$ $1 0 1 1 1$

= $1$ $1$ carry $+ 0111$ $+ 0111$
= $0001 0111 = 17$ $0001 0111 = 17$``````

In this example, we will add two decimal numbers,

`````` $214 + 389 = 603$ $214 + 389 = 603$ $0 0 1 0 0 0 0 1 0 1 0 0 = 214$ $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 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 1 0 1 0 1 1 0 1$ $0 1 1 0 0 1 1 0$ $0 1 1 0 0 1 1 0$
____________________________________ $0 1 1 0 0 0 0 0 0 0 1 1 = 603$ $0 1 1 0 0 0 0 0 0 0 1 1 = 603$``````

### References

• John.F.Wakerly. 2008. Digital Design: Principles And Practices, 4/E. Pearson Education, India.
• Mano, M. Morris. 1984. Digital Design. Pearson.