COBOL COMP-3 (PACKED-DECIMAL) Byte Length Formula & Hex Decoder
Mainframe COMP-3 (USAGE PACKED-DECIMAL) packs two decimal digits per byte (BCD nibbles ..9) with the trailing low nibble reserved for the algebraic sign (C positive, D negative, F unsigned).
1. Exact COMP-3 Byte Width Formula & Lookup Table
For any COBOL numeric picture with N total digits (summing integer digits before V and fractional digits after V; the implied S and V symbols consume zero nibbles):
packedBytes = floor(N / 2) + 1
| COBOL Clause | Total Digits (N) | Packed Bytes | Example Value | Raw Hex in File |
|---|---|---|---|---|
PIC S9(3) COMP-3 | 3 | 2 bytes | +125 | 12 5C |
PIC S9(5)V99 COMP-3 | 7 | 4 bytes | +450.25 | 00 45 02 5C |
PIC S9(7)V99 COMP-3 | 9 | 5 bytes | -120.00 | 00 00 12 00 0D |
PIC 9(8) COMP-3 | 8 | 5 bytes (leading 0 pad) | 20261113 | 02 02 61 11 3F |
PIC S9(13)V99 COMP-3 | 15 | 8 bytes | +9850.75 | 00 00 00 00 09 85 07 5C |
2. Trailing Sign Nibbles (0xC, 0xD, 0xF) & Why Text Editors Corrupt Them
0xC(or0xA/0xE): Signed positive value (e.g.,00 01 42 55 0C=+1425.50).0xD(or0xB): Signed negative value (e.g.,00 00 12 00 0D=-120.00).0xF: Unsigned positive value (`PIC 9(...) COMP-3` without `S`).

Frequently Asked Engineering Questions
Why does PIC S9(8) COMP-3 take 5 bytes instead of 4?
Because 8 digits occupy 8 nibbles, and the mandatory trailing sign nibble requires a 9th nibble, rounding up to 5 full bytes with one leading zero-pad high nibble.
Inspect, Decode, Diff & PCI-Scrub Mainframe Dumps Offline in Your JetBrains IDE
Never upload regulated banking, card-network, or insurance .ebcdic extracts or proprietary .cpy schemas into browser hex viewers. EbcdicPrism Copybook Viewer runs 100% air-gapped inside IntelliJ IDEA, DataGrip, PyCharm, Rider, GoLand, and WebStorm with a forever-free core tier and a 14-day [Pro] trial.