Vocademy

Binary-coded Decimal

Some computer processors can work directly with binary-coded decimal (BCD) numbers. BCD uses four-bit groups—one-half byte each—to hold the binary equivalent of decimal digits. Here is a chart that shows the BCD groups, and their decimal equivalents. Binary numbers not used for BCD are shown with an X, and greyed out.

0 0000   8 1000
1 0001   9 1001
2 0010   X 1010
3 0011   X 1011
4 0100   X 1100
5 0101   X 1101
6 0110   X 1110
7 0111   X 1111

Decimal numbers and their BCD equivalents

Floating point decimal numbers are represented in BCD, where the first byte represents an exponent, essentially telling where to place the decimal point. Here is the number 25.12 stored in floating point BCD. Every other byte is highlighted so you can see that each byte holds a two-digit BCD number.

01000010 0010 0101 0001 0010 0000 0000 0000 0000 0000 0000

Here is the number 25.12, expressed as a five-byte BCD number. The exponent is an extra byte of straight binary.

Notice that each byte holds two digits. Here the first four digits are 2512, which are 0010, 0101, 0001, and 0010, respectively, making the number 2512000000.

The most significant bit of the first byte is the sign of the significand; zero means the significand is positive. The following seven bits represent the exponent expressed as a signed integer in excess 64 notation. The exponent is +2, which is 0000010 in binary. Adding 64 to this gives us 1000010 or +66. Since 64 + 2 = 66, this says to place the decimal point two places from the left. The remaining five bytes hold a 10-digit decimal number expressed as BCD. This is the significand without the decimal point. Therefore, the significand is 2512. The exponent says to place the decimal point two places from the left, making the final number 25.12.

An alternate method uses scientific notation. This assumes the decimal point is one place from the left, which makes the exponent one less than that described above. In that case, think of the exponent as saying how many spaces to move the exponent. The only difference is the assumed location of the decimal point before applying the exponent.

Vocademy