Densely packed decimal

Densely packed decimal (DPD) is an efficient method for binary encoding decimal digits.

The traditional system of binary encoding for decimal digits, known as binary-coded decimal (BCD), uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth (since four bits can store 16 states and are being used to store only 10). Densely packed decimal is a more efficient code that packs three digits into 10 bits using a scheme that allows compression from, or expansion to, BCD with only two or three gate delays in hardware.[1]

The densely packed decimal encoding is a refinement of Chen–Ho encoding; it gives the same compression and speed advantages, but the particular arrangement of bits used confers additional advantages:

History

In 1971, Tien Chi Chen and Dr. Irving T. Ho devised a lossless prefix code (now known as Chen–Ho encoding) which packed three decimal digits into 10 binary bits using a scheme which allowed compression from or expansion to BCD with only two or three gate delays in hardware. Densely packed decimal is a refinement of this, by Mike Cowlishaw, which was incorporated into the IEEE 754-2008 standard for decimal floating-point.

Encoding

Like Chen–Ho encoding, DPD encoding classifies each decimal digit into one of two ranges, depending on the most significant bit of the binary form: "small" digits have values 0 through 7 (binary 0000–0111), and "large" digits, 8 through 9 (binary 1000–1001). Once it is known or has been indicated that a digit is small, three more bits are still required to specify the value. If a large value has been indicated, only one bit is required to distinguish between the values 8 or 9.

When encoding, the most significant bit of each of the three digits to be encoded select one of 8 coding patterns for the remaining bits, according to the following table. The table shows how, on decoding, the ten bits of the coded form in columns b9 through b0 are copied into the three digits d2 through d0, and the remaining bits are filled in with constant zeros or ones.

Densely packed decimal encoding rules[2]
DPD encoded value Decimal digits
b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 d2 d1 d0 Values encoded Control Description
abcdef0ghi0abc0def0ghi(0–7) (0–7) (0–7) b3=0
Three small digits
abcdef100i0abc0def100i(0–7) (0–7) (8–9) b3=1, b2b1≠11
Two small digits,
one large
b2b1=00, d0=large
abcghf101i0abc100f0ghi(0–7) (8–9) (0–7) b2b1=01, d1=large
ghcdef110i100c0def0ghi(8–9) (0–7) (0–7) b2b1=10, d2=large
ghc00f111i100c100f0ghi(8–9) (8–9) (0–7) b3=1, b2b1=11, b6b5≠11
One small digit,
two large
b6b5=00, d0=small
dec01f111i100c0def100i(8–9) (0–7) (8–9) b6b5=01, d1=small
abc10f111i0abc100f100i(0–7) (8–9) (8–9) b6b5=10, d2=small
xxc11f111i100c100f100i(8–9) (8–9) (8–9) b3=1, b2b1=11, b6b5=11
Three large digits

Bits b7, b4 and b0 (c, f and i) are passed through the encoding unchanged, and do not affect the meaning of the other bits. The remaining 7 bits can be considered a 7-bit encoding for 3 base-5 digits.

Bits b8 and b9 are not needed and ignored when decoding DPD groups with three large digits (marked as "x" in the last row of the table above), but are filled with zeros when encoding.

The 8 decimal values whose digits are all 8s or 9s have four codings each. The bits marked x in the table above are ignored on input, but will always be 0 in computed results. (The 8×3 = 24 non-standard encodings fill in the gap between 103=1000 and 210=1024.)

Examples

This table shows some representative decimal numbers and their encodings in BCD, Chen–Ho, and densely packed decimal (DPD):

Decimal BCD Chen–Ho DPD
005 0000 0000 0101 000 000 0101 000 000 0101
009 0000 0000 1001 110 000 0001 000 000 1001
055 0000 0101 0101 000 010 1101 000 101 0101
079 0000 0111 1001 110 011 1001 000 111 1001
080 0000 1000 0000 101 000 0000 000 000 1010
099 0000 1001 1001 111 000 1001 000 101 1111
555 0101 0101 0101 010 110 1101 101 101 0101
999 1001 1001 1001 111 111 1001 001 111 1111

See also

References

  1. Cowlishaw, M. F. (2000-10-03). "Summary of Densely Packed Decimal encoding". Retrieved 2008-09-10.