Sometimes it is important to know which column a denary digit is. For example if its in the tens column or the hundreds. We may not wish to do any calculations on this number. For example a product code. We may not wish to add or subtract product codes but we may wish to look at each part of the code separately. Consider the following code.

  • First digit- Country code
  • Second and third digit - Manufacturer code
  • Fourth and fifth digit - product type

So the number 24587 will have

  • 2 as country code
  • 45 as manufacturer code
  • 87 as product code

If we stored the above number as a binary number, 110000000001011 , then how can we tell that it has a country code of 2? It is very difficult to get that information out of that binary code. As such we could store it as a string of characters.

Each character in a string is one byte long. So to store the above code we will need 5 bytes. This seems inefficient as the biggest digit we will store in each byte is 9. Why not use a single hexadecimal value to store it?

A hexadecimal value requires just four bits to store itself. As such we can store two hexadecimal values per byte and as we have seen, it is very simple to get the decimal values from these hexadecimal values.

The binary coded decimal effectively stores each digit as 4 bits. Lets work through our example.

Digit

2

4

5

8

7

Hexadecimal value

2

4

5

8

7

Converting these values to binary we get -

Digit

2

4

5

8

7

Binary Value

0010

0100

0101

1000

0111

As such the fully coded version will be -

0010 0100 0101 1000 0111