Wednesday, December 7, 2011

COBOL:  Internal representation of numeric items

Below examples explains how various data types are internally stored in memory

PIC S9999 DISPLAY
Value : + 1234
Internal representation:   F1 F2 F3 C4

Value : - 1234
Internal representation:   F1 F2 F3 D4

Value :   1234
Internal representation:   F1 F2 F3 C4

PIC 9999 DISPLAY
Value :   1234
Internal representation:   F1 F2 F3 F4


PIC S9999 DISPLAY SIGN LEADING
Value : + 1234
Internal representation:   C1 F2 F3 F4

Value : - 1234
Internal representation:   D1 F2 F3 F4

PIC S9999 DISPLAY SIGN LEADING SEPARATE
Value : + 1234
Internal representation: 4E F1 F2 F3 F4

Value : - 1234
Internal representation: 60 F1 F2 F3 F4

PIC S9999 DISPLAY SIGN TRAILING SEPARATE
Value : + 1234
Internal representation: F1 F2 F3 F4 4E

Value :  - 1234
Internal representation: F1 F2 F3 F4 60


PIC S9999 BINARY /PIC S9999 COMP/PIC S9999 COMP-4
Value :  + 1234
Internal representation:   04 D2

Value :  - 1234
Internal representation:   FB 2E

PIC S9999 COMP-5
Value :  + 123451
Internal representation:   30 39

Value :  - 123451
Internal representation:   CF C7


PIC 9999  COMP-5
Value :   600001
Internal representation:   EA 60

The example demonstrates that COMP-5 data items can contain values of magnitude up to the capacity of the native binary representation (2, 4, or 8 bytes), rather than being limited to the value implied by the number of 9s in the PICTURE clause.


PIC 9999  BINARY/PIC 9999  COMP/PIC 9999  COMP-4
Value :   1234
Internal representation:    04 D2

PIC S9999 PACKED-DECIMAL/PIC S9999 COMP-3
Value :  + 1234
Internal representation:   01 23 4C

Value :  - 1234
Internal representation:   01 23 4D

PIC 9999  PACKED-DECIMAL/PIC 9999  COMP-3
Value :  + 1234
Internal representation:   01 23 4F

Value :  - 1234
Internal representation:   01 23 4F

COMP-1
Value :  + 1234
Internal representation: 43 4D 20 00

Value :  - 1234
Internal representation: C3 4D 20 00

COMP-2
Value :  + 1234
Internal representation: 43 4D 20 00 00 00 00 00

Value :  - 1234
Internal representation:C3 4D 20 00 00 00 00 00

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.