In the last session, we discussed how binary arithmetic works, how two binary digits can be add up to each other and also how computers may calculate subtraction with the two’s complement notation.

Learning Objectives

Binary Coded Decimal

Have you ever tried this in Python before? 0.4 - 0.3

image.png

The result is very surprising as it is not 0.1 exactly, but with a small remainder.

It is very surprising when I first noticed it, and the reason behind it is if we used simple binary conversion for decimal digits, a lot of times we may not obtain the exact number (More details will be covered in A2 section 16.03), but for the scenario requires precise calculations like calculator and exchange rate market, this could potentially be a huge issue. One of the solutions is to use binary coded decimal (BCD) and we will see why it works better in a second.

Binary Coded Decimal table

As there is 10 different options for one denary digits (i.e., range from 0 - 9), 4 bits of binary is required to represent 1 denary digit. The table shows how denary values is represented in the form of BCD.

image.png

This leaves 1010 to 1111 unused in this representation, as there is no corresponding single digit denary that could be represented, and this could actually cause problems later on in the addition.

Binary Coded Decimal (BCD) VS Traditional Binary

You may ask, “What is the difference between BCD and traditional binary?”

Well, traditional binary considers the denary digit as a whole, while BCD breaks the denary down into each digit. Let’s see an example of how denary number 13 can be represented with both forms.

image.png