100% Offline Reference COMP-3 Reference

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 ClauseTotal Digits (N)Packed BytesExample ValueRaw Hex in File
PIC S9(3) COMP-332 bytes+12512 5C
PIC S9(5)V99 COMP-374 bytes+450.2500 45 02 5C
PIC S9(7)V99 COMP-395 bytes-120.0000 00 12 00 0D
PIC 9(8) COMP-385 bytes (leading 0 pad)2026111302 02 61 11 3F
PIC S9(13)V99 COMP-3158 bytes+9850.7500 00 00 00 09 85 07 5C

2. Trailing Sign Nibbles (0xC, 0xD, 0xF) & Why Text Editors Corrupt Them

Never Convert Binary EBCDIC Files Using Naive Text FTP (ASCII Mode)! In `COMP-3`, `0x0D` is a packed digit `0` + negative sign `D`, and `0x15` is packed digits `15` — NOT carriage-return or EBCDIC `NL` line breaks! Running ASCII-mode FTP or `iconv` across a mixed EBCDIC + `COMP-3` file irrecoverably destroys packed monetary columns.
EdiPrism Offline Inspector — Zero Network Calls
COBOL COMP-3 Packed Decimal Byte Length Formula & Hex Unpacking Guide — EdiPrism inside JetBrains IDE with EdiPrism

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.

Install EbcdicPrism in JetBrains IDE → GitHub Docs & Issue Tracker