wire / wire-format / bcd
BCD (Binary-Coded Decimal) encodes each decimal digit (0-9) as a 4-bit nibble. Packed BCD: two digits per byte (high nibble = tens, low nibble = ones). Unpacked BCD: one digit per byte (low nibble = digit, high nibble = 0 or zone). Used in financial calculations, real-time clocks, and legacy systems.
aka: BCD (Binary-Coded Decimal)
spec: BCD (Binary-Coded Decimal)
BCD (Binary-Coded Decimal) encodes each decimal digit (0-9) as a 4-bit nibble. Packed BCD: two digits per byte (high nibble = tens, low nibble = ones). Unpacked BCD: one digit per byte (low nibble = digit, high nibble = 0 or zone). Used in financial calculations, real-time clocks, and legacy systems.
| field | size | meaning |
|---|---|---|
| Packed BCD | 1 byte per 2 digits | High nibble = tens digit, low nibble = ones digit. E.g., 0x42 = decimal 42. |
| Unpacked BCD | 1 byte per digit | Low nibble = digit, high nibble = 0 (or zone nibble 0x3 for ASCII). E.g., 0x04 = digit 4. |
| Sign | 1 nibble | For signed BCD: the last nibble can be 0xC (+), 0xD (-), or 0xF (unsigned). |
| Range (packed, n bytes) | n bytes | 2n decimal digits. E.g., 4 bytes = 8 digits (0-99999999). |
example:
42
Packed BCD: 0x42 = decimal 42
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/bcd
or /wire-format/bcd.json