BCD number

Top  Previous  Next

 

In the early times of computer technic, when the HMI (human machine interface) consisted of small lamps and handwheel-switches, one realized that people could hardly read the binary numbers of the machines and that it is difficult the other way round to draw a binary signal out of multidigit handwheel-switches. That is why the binary coded decimal number was invented, a chimera out of both representations. You just take each single digit of a number that is displayed in the decimal system and translate that one into a nibble (half byte) in binary representation. Nearly like this:

 


159        ->

0001

1

0101

5

1001

9

 

With a little practice man can learn the binary representation of the numbers from 0 up to 9, and also handwheel-switches can be constructed with limited effort so that they code this small counting range binary. Unfortunately, this inexpressible data format with which it is quite hard to calculate survived until now. The only comfort is that the waste of memory capacity which is combined with this does not matter anymore.

 

The easiest way to note a BCD-constant in the area of 0 - 999 is to use the counter format C#xyz, e.g. C#642.

 

A BCD-number will be interpreted as negative if all four bits of the most significant nibble equal 1. So you note -53(bcd) as W#16#F053, for example.

 

Seven-digit BCD-numbers can be noted by the use of the DW#16#-format.

 

Converting between BCD-numbers and binary format there are the following functions:

BTI

3 digit BCD-number with sign -> integer

BTD

7 digit BCD-number with sign -> double integer

ITB

binary coded number from -999 up to +999 -> BCD

DTB

binary coded number from -9.999.999 up to +9.999.999 -> BCD