Decimal -> BCD

It is necessary to explain some terms for the correct understanding of this section. The pure binary code is based on a rule (power of two), whilst the BCD codes are based on a table where the decimal numbers from 0 to 9 are shown and their corresponding "translations" in BCD. There are several types of BCD:

  • Pure BCD: Binary Code Digit, it is a standard to represent decimal numbers in binary system, where each decimal digit is coded as a sequence of 4 bits.
  • BCDS XS3: the conversion is done adding 3 units to the decimal number that we want to transform into a binary number.
  • Aiken: code similar to natural BCD where the "weights" or "values" are distributed in a different manner. In the natural BCD, the weights are: 8-4-2-1, in the Aiken code, the distribution is: 2-4-2-1.

If the previous codes are based on a rule, these are based on a table. The method consists on replacing each digital number by the 4 corresponding bits.

Decimal

BCD puro

BCD XS3

Aiken

BCD 5421

0

0000

0011

0000

0000

1

0001

0100

0001

0001

2

0010

0101

0010

0010

3

0011

0110

0011

0011

4

0100

0111

0100

0100

5

0101

1000

1011

1000

6

0110

1001

1100

1001

7

0111

1010

1101

1010

8

1000

1011

1110

1011

9

1001

1100

1111

1100

Thus, in BCD 13 is written as 1 (0001) followed by 3 (0011): 13 in decimal is written as 00010011 in BCD. The same number in XS3 is written as 01000110.

To pass from decimal to binary, and vice versa, you simply need the conversion table (dictionary) in front of you, or to know it by hard. The BCD table is very simple.