IBM Packed Decimal Numbers

Packed decimal is a method of storing integers on IBM mainframes in a format that stores the number using an odd number of base 10 digits and a final sign character.

This is opposed to the traditional method of converting a number from base 10 to base 2 and storing it as a binary number.

A packed decimal number is from 1 to 16 bytes long.

The last byte of all packed numbers contains a 4 bit digit followed by a 4 bit sign code. The 4 bit digit is a decimal number from 0 to 9 and comes from the packed decimal digit table. The 4 bit sign comes from the packed decimal sign table. Their are 6 values which are legal for signs from decimal 10 to decimal 15. Four of the values are used for a positive sign, the other two values are used for a negitive sign. The preferred positive sign is a decimal 12. The preferred negitive sign is a decimal 13.

For packed decimal numbers from 2 to 16 bytes long each byte execpt the last byte contains two 4 bit decimal digits from the packed decimal digit table.

IBM computers using the packed decimal instructions of the 360 and 370 instruction set can perform math operations on packed numbers. There are instructions to convert packed decimal numbers to binary, and to convert packed decimal numbers to human readable EBCDIC numbers which is the default character set on IBM mainframes.

Packed decimal numbers can be easily read in a hex memory dump without the need to convert the number from binary to base 10 because the packed decimal number is stored as a base 10 number.

Packed decimal numbers take more memory to store a value then binary numbers. It also takes the hardware more computer time to perform math operations on packed decimal numbers then binary numbers.


Packed Decimal Sign and Digit Table p2

The following table shows all possible 4 bit values used to build IBM packed decimal numbers. The first 10 values are used to build the digits of packed decimal numbers and are used to build the digits zero thru nine. The last 6 values are used to build the sign value of the packed decimal number. A decimal 12 is the preffered value for a plus sign and a decimal 13 is the preffered value for a minus sign. But any of the sign values will work. Oddly IBM defined four values that can be used for plus signs and only two values that can be used for negitive signs.

Packed Decimal Numbers
Digits and signs used to build packed decimal numbers
Digit or Sign
Type
Digit/Sign
Value
DecimalHexBinaryOctal
0 DIGIT 0 00 0000 00
1 DIGIT 1 01 0001 01
2 DIGIT 2 02 0010 02
3 DIGIT 3 03 0011 03
4 DIGIT 4 04 0100 04
5 DIGIT 5 05 0101 05
6 DIGIT 6 06 0110 06
7 DIGIT 7 07 0111 07
8 DIGIT 8 08 1000 10
9 DIGIT 9 09 1001 11
+ SIGN 10 0A 1010 12
- SIGN 11 0B 1011 13
+ preffered SIGN 12 0C 1100 14
- preffered SIGN 13 0D 1101 15
+ SIGN 14 0E 1110 16
+ SIGN 15 0F 1111 17


Packed Decimal sign table p3

This table is a subset of the prior table and only contains the 4 bit values used to build the sign of packed decimal numbers.

Packed Decimal Numbers
Signs used to build packed decimal numbers
Sign
Value
DecimalHexBinaryOctal
Illegal 0 00 0000 00
Illegal 1 01 0001 01
Illegal 2 02 0010 02
Illegal 3 03 0011 03
Illegal 4 04 0100 04
Illegal 5 05 0101 05
Illegal 6 06 0110 06
Illegal 7 07 0111 07
Illegal 8 08 1000 10
Illegal 9 09 1001 11
+ 10 0A 1010 12
- 11 0B 1011 13
+ preffered 12 0C 1100 14
- preffered 13 0D 1101 15
+ 14 0E 1110 16
+ 15 0F 1111 17


Packed Decimal Digit Table p4

This table is a subset of the first packed decimal table and only contains the 4 bit values used to build the digits of packed decimal numbers.

Packed Decimal Numbers
Digits used to build packed decimal numbers
Digit
Value
DecimalHexBinaryOctal
0 0 00 0000 00
1 1 01 0001 01
2 2 02 0010 02
3 3 03 0011 03
4 4 04 0100 04
5 5 05 0101 05
6 6 06 0110 06
7 7 07 0111 07
8 8 08 1000 10
9 9 09 1001 11
Illegal 10 0A 1010 12
Illegal 11 0B 1011 13
Illegal 12 0C 1100 14
Illegal 13 0D 1101 15
Illegal 14 0E 1110 16
Illegal 15 0F 1111 17


Index

1