Binary-coded Decimal Numbers


One of the lesser-used data types supported by many math coprocessors is the Binary-Coded Decimal (hence BCD) type, which is more precisely known as a packed binary-coded decimal number. A packed Binary-coded decimal number can hold two decimal digits (0 to 9) in each byte, while an unpacked form stores only a single decimal digit per byte. Note that of the four bits in half a byte there is no problem in storing any of the ten decimal digits; four bits can be used to represent any of 16 different values. On the Intel 80x87 family of math coprocessors the packed BCD type is implemented to use all 80 bits (ten bytes) of a coprocessor register. Motorola 68081/2 Floating Point Coprocessors have a packed decimal real (of 96 bits) that serves essentially the same purpose.

Not all of the 80 bits in each Intel coprocessor register can be used. The most significant bit (bit 79) is used to hold the sign, with 1 indicating a negative number and 0 indicating a positive number. The remaining bits of the most significant byte (bits 72 through 78) are unused. This leaves bits 0 through 71 (9 bytes) to hold 18 decimal digits. Figure 1 shows the layout of a math coprocessor register when it contains a BCD number.