Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DISPLAY HEXADECIMAL VALUE 2

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
0
0
CA
Hi,
Is there a way a could display the hexadecimal value of a variable ?
In my program i do a move from A to B, then display B.
A and B are packed data (julian dates)
thanks
 
Claudeb,

If you mean 'how do I display the decimal value?' you just need to define a 'normal' numerical PIC 9(??) field, when you move (A or B) into it the conversion will be done for you.
If you mean 'how do I display the hexadecimal value?' (wish is what you say but I don't think what you mean) you could use EXHIBIT on the field or if your IDE allows you to interrogate the field while 'animating' the program you could do it that way.

Good Luck.
 
To display hexadecimal values you can use a program like this:

000010*$CALL
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. BIN2HEX.
000300 ENVIRONMENT DIVISION.
000400 CONFIGURATION SECTION.
000500 SOURCE-COMPUTER. IBM-PC.
000600 OBJECT-COMPUTER. IBM-PC.
000700 SPECIAL-NAMES.
000800 DECIMAL-POINT IS COMMA.
000900 INPUT-OUTPUT SECTION.
001000 FILE-CONTROL.
001100 DATA DIVISION.
001200 FILE SECTION.
001300 WORKING-STORAGE SECTION.
001400 01 HULPVELDEN.
001500 03 SUB-STRING PIC S9(4) COMP-5.
001600 03 TABEL-HEX.
001700 05 FILLER PIC X(32) VALUE
001800 '000102030405060708090A0B0C0D0E0F'.
001900 05 FILLER PIC X(32) VALUE
002000 '101112131415161718191A1B1C1D1E1F'.
002100 05 FILLER PIC X(32) VALUE
002200 '202122232425262728292A2B2C2D2E2F'.
002300 05 FILLER PIC X(32) VALUE
002400 '303132333435363738393A3B3C3D3E3F'.
002500 05 FILLER PIC X(32) VALUE
002600 '404142434445464748494A4B4C4D4E4F'.
002700 05 FILLER PIC X(32) VALUE
002800 '505152535455565758595A5B5C5D5E5F'.
002900 05 FILLER PIC X(32) VALUE
003000 '606162636465666768696A6B6C6D6E6F'.
003100 05 FILLER PIC X(32) VALUE
003200 '707172737475767778797A7B7C7D7E7F'.
003300 05 FILLER PIC X(32) VALUE
003400 '808182838485868788898A8B8C8D8E8F'.
003500 05 FILLER PIC X(32) VALUE
003600 '909192939495969798999A9B9C9D9E9F'.
003700 05 FILLER PIC X(32) VALUE
003800 'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'.
003900 05 FILLER PIC X(32) VALUE
004000 'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'.
004100 05 FILLER PIC X(32) VALUE
004200 'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'.
004300 05 FILLER PIC X(32) VALUE
004400 'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'.
004500 05 FILLER PIC X(32) VALUE
004600 'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'.
004700 05 FILLER PIC X(32) VALUE
004800 'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'.
004900 03 FILLER REDEFINES TABEL-HEX.
005000 05 FILLER PIC XX.
005100 05 HEX-OMSCHRIJVING OCCURS 255
005200 PIC XX.
005300
005400 03 TEMP.
005500 05 FILLER PIC X VALUE LOW-VALUE.
005600 05 TESTWAARDE PIC X.
005700 03 SUB REDEFINES TEMP PIC S9(4) COMP.
005800
005900 LINKAGE SECTION.
006000 01 LNK-LENGTE-STRING PIC S9(4) COMP-5.
006100
006200 01 LNK-TE-CONVERTEREN-STRING.
006300 03 LNK-NORMAAL-TEKEN OCCURS 1 TO 16000
006400 DEPENDING ON LNK-LENGTE-STRING
006500 PIC X.
006600
006700 01 LNK-HEX-STRING.
006800 03 LNK-HEX-TEKEN OCCURS 1 TO 32000
006900 DEPENDING ON LNK-LENGTE-STRING
007000 PIC XX.
007100
007200 PROCEDURE DIVISION.
007300 HOOFD SECTION.
007400 ENTRY 'USR_BIN2HEX' USING LNK-LENGTE-STRING
007500 LNK-TE-CONVERTEREN-STRING
007600 LNK-HEX-STRING.
007700 HOO-01.
007800 PERFORM VARYING SUB-STRING FROM +1 BY +1 UNTIL
007900 SUB-STRING > LNK-LENGTE-STRING
008000 MOVE LNK-NORMAAL-TEKEN (SUB-STRING) TO TESTWAARDE
008100 MOVE HEX-OMSCHRIJVING (SUB) TO
008200 LNK-HEX-TEKEN (SUB-STRING)
008300 END-PERFORM.
008400 HOO-99.
008500 GOBACK.


Have fun!

I hope this helps
 
There is a good example of using COBOL for displaying hexadecimal information (i.e. a formatted dump) at the following URL...
...
The COBOL source code for a demo and a callable COBOL routine are included as ZIPped files for downloading... could save you some typing time...
Good Luck...
 
Hi,

Here's something I use to display main storage addresses that may help. I used 8 bytes, naturally you can use any length you need.

The move from a packed to an unpacked field changes every byte in the field (except the last) to "Fx". The nibbles in the last byte get flipped (X'0C' becomes X'C0'). Since we don't want that to happen to the data we're interested in, that dummy byte is added to the end of the field and is ignored in the display.

Since X'FA', X'FF' etc. won't display as A, F, etc., the INSPECT is used to convert them.

Code:
           05  WS-WORK. 
           10  WS-YOUR-FLD-WRK         PIC X(008).
           10  FIL                     PIC X(001) VALUE 
                                                   X'0C'.
           10  WS-WORK-PACKED          REDEFINES
               WS-WORK                 PIC 9(009) COMP-3. 

           05  WS-WORK-UNPACKED        PIC 9(009).
           05  REDEFINES WS-WORK-UNPACKED.
           10  WS-WORK-UNPACKED-8      PIC 9(008).



       100-CONVERT-HEX-DATA.
      *--------------------------------------------------      *===>  CONVERTS HEX DATA FOR DISPLAY PURPOSES
      *      E.G. X"04FB" ====> X"F0F4C6C2" OR 04FB CHAR
      *--------------------------------------------------
           MOVE    your-hex-field TO WS-YOUR-FLD-WRK
           MOVE    WS-WORK-PACKED TO WS-WORK-UNPACKED
           INSPECT WS-WORK-UNPACKED CONVERTING
                   X"FAFBFCFDFEFF"  TO  "ABCDEF"
           DISPLAY 'HEX FIELD >' WS-WORK-UNPACKED-8 '<'
           .
 
Hi,

Perhaps I didn't explain well the usage of the BIN2HEX program. You can call it, using the length of the data to convert, the input string and the output string. It can handle a size from 1 to 16000.

The converted string - the third parm - is displayable.

You can also build this source into your own application, but it is also possible to put it in a library. That is what I do on the PC. HEX2BIN, BIN2HEX, etc. etc.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top