Productivity and Utilities

Packed Decimal (COMP-3) Converter

Choose a direction, then enter the bytes as hex or the number to pack.

Your numbers

Convert

Spaces are fine. The last digit is the sign: C or F positive, D negative.

For PIC S9(5)V99 enter 2. Example figures throughout.

Result

Number

-123.45

3 bytes, 5 digits, negative

Sign
negative
Digits
5

Field

PartValue
Number-123.45
Signnegative
Digits5
Bytes3
Decimal places2
How this was calculated
  1. Each byte holds two decimal digits, one in each half. The last half-byte is the sign instead of a digit.
  2. The sign half is C, A or E for positive, D or B for negative and F for unsigned.
  3. The decimal point sits 2 places from the right. It is not stored in the bytes.
  • This reads one packed field. Fields in a record file also depend on the record layout, and files moved from a mainframe may need a code page conversion for the text fields around them.

Calculated using SumPanda.com · https://sumpanda.com/packed-decimal-comp-3-converter/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the packed decimal (comp-3) converter

  1. Choose Hex to number or Number to hex.
  2. To decode, type the bytes as hex, with or without spaces, and the number of decimal places that the field layout implies.
  3. To encode, type the number, the decimal places and optionally the total digits of the field, and choose a signed or unsigned layout.
  4. Read the number, or the packed bytes, with the sign half-byte and the size.

Formula

Each byte holds two decimal digits, one in each half

The last half-byte is the sign: C or A or E positive, D or B negative, F unsigned

The decimal point sits scale places from the right and is not stored

A field with an even number of digits gets a leading zero so that the digits and the sign fill whole bytes.

Reading and writing a few fields

The bytes 12 34 5D with 2 decimal places hold the digits 12345 and the sign D, so the number is -123.45. The bytes 00 12 34 5C with 2 decimal places are +123.45.

To pack -1234.56 with 2 decimal places, the digits are 123456, a leading zero is added and the sign D is appended, giving 01 23 45 6D. A COBOL field PIC S9(5)V99 COMP-3 holds 7 digits and the sign in 4 bytes, so -12345.67 packs to 12 34 56 7D, and 42 with 7 digits packs to 00 00 04 2C. An unsigned 7 packs to 7F.

Where packed decimals are found

COMP-3 is the name for packed decimal storage in COBOL and in many mainframe and banking systems. It stores money and other exact decimal values without the rounding that binary floating point brings. When a file from such a system lands on another computer, the packed fields look like garbage in a text editor because their bytes are not characters. Looking at the bytes in hex and decoding them gives the number back.

The size of the field follows from the picture clause: the number of bytes is the digits divided by two, rounded down, plus one. Seven digits take four bytes and eight digits take five, since the extra digit needs another byte for its zero.

Checking a decoded field

If a decode fails, the usual cause is that the bytes are not a packed field at all. A digit half-byte above 9 is an error, and so is a last half-byte below A. The messages say which digit failed. Files moved from a mainframe may also use a different code page for the text fields around the packed ones, which this tool does not convert.

To look at raw bytes, use the Hex Viewer or the Binary Calculator. If the bytes were sent as text, the Base64 Encoder and Decoder can get them back. A file with fixed record layouts can be split into columns with the Fixed Width to CSV Converter, and the CSV to Fixed Width Converter goes the other way.

Assumptions and limits

  • The number of decimal places is taken from you. It is not stored in the bytes.
  • A number with more decimals than the scale is rejected and not rounded.
  • A zero is never shown as negative, even when the sign half-byte is D.
  • The values shown are examples for the demonstration.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

What do the sign letters mean?

C and A and E mean positive, D and B mean negative, and F means unsigned. C and D are the ones most programs write.

Why is there a zero in front of my number?

The digits plus the sign half-byte must fill whole bytes, so a zero is added when the count of half-bytes would be odd.

What is the scale?

It is the number of digits after the decimal point, the V in a picture such as S9(5)V99. It is part of the record layout, not the bytes.

Can I decode several fields at once?

Not at once. Decode one field at a time, using the byte positions from your record layout.