Decimal Numbers

There are two formats for decimal numbers:

1. Zoned Decimal
2. Packed Decimal

Zoned Decimal Numbers

```-  Generally used for input/output

-  Represent one decimal digit per byte

-  Each byte of is made up of two hex digits

left  ->  zone digit       right ->  numeric digit

- The numeric digit is the number represented by the byte

- The zone digit of all but the RIGHTMOST byte must be F

- The zone digit of the rightmost byte is used to indicate the sign
of the number

A, C, E, or F    positive number
B or D           negative number

F1F2F3F4   zoned decimal representation of +1234

F1F2F3B4   zoned decimal representation of -1234

- Can be generated on a DC statement by using a storage class of Z

- the initial value can contain a sign or a decimal point

- if the sign is omitted, assumed to be positive

- if plus sign is specified, rightmost zone digit is C

- if negative sign is specified, rightmost zone digit is D

- if a decimal point is specified, treated as an implied
decimal point

DC   2Z'-1'         D1D1
DC   Z'+2'          C2
DC   Z'2'           C2
DC   ZL3'4'         F0F0C4
DC   2ZL2'-9'       F0D9F0D9
DC   Z'1.10'        F1F1C0

- Maximum zoned decimal number can have 16 digits
```

Packed Decimal Numbers

```-  Used for arithmetic

-  Each byte, except for the rightmost, represents two decimal digits

-  The rightmost byte contains a decimal digit and the sign digit

left  ->  numeric digit      right ->  sign digit

-  The sign digit is used to indicate the sign of the number

A, C, E, or F    positive number
B or D           negative number

-  To represent a number:

1. Move the sign to the right (end) of the number
2. If there is an even number of digits, add a zero on the left
3. Change the sign to an appropriate sign digit

To represent -1234:

1. 1234-
2. 01234-
3. 01 23 4D

- Can be generated on a DC statement by using a storage class of P

- the initial value can contain a sign or a decimal point

- if the sign is omitted, assumed to be positive

- if plus sign is specified, rightmost sign digit is C

- if negative sign is specified, rightmost sign digit is D

- if a decimal point is specified, treated as an implied
decimal point

DC   2P'-1'         1D1D
DC   P'+2'          2C
DC   P'2'           2C
DC   PL3'4'         00004C
DC   2PL2'-9'       009D009D
DC   P'1.10'        110C

- Maximum packed decimal number can have 31 digits
```