Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

convert hex data to char

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
lcmontanez

New User


Joined: 19 Jun 2007
Posts: 50
Location: Chicago

PostPosted: Sat Jan 17, 2009 1:09 am    Post subject: convert hex data to char
Reply with quote

Is there a function or technique to convert a X'10', X'11', x'12, etc to
char/numeric 10, 11. 12, etc?
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jan 17, 2009 2:14 am    Post subject:
Reply with quote

Hello,

Yes, set up an array of 2-byte entries with values from '00' to 'FF'.

Use the byte with the hex-value as the displacement into the array and you have the value for any possible one-byte hex-value.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sat Jan 17, 2009 2:44 am    Post subject:
Reply with quote

Where are these "HEX" values coming from?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Sat Jan 17, 2009 3:22 am    Post subject:
Reply with quote

You can also resolve the two-byte equivalent of the one-byte hex-value on the fly. As your requirement states, the HEX-VALUE can be in the range of X'00' through X'FF', resolving to a two-byte CHARACTER value of C'00' through C'FF'.

Code:

03  WS-HEX-BYTE PIC X(01).
03  WS-PACKED PIC 9(03) COMP-3.
03  WS-PACKED-V9 REDEFINES WS-PACKED PIC 9(02)V9 COMP-3.
03  WS-PACKED-X REDEFINES WS-PACKED PIC X(02).
03  WS-DISPLAY PIC 9(03).
03  WS-DISPLAY-V9 REDEFINES WS-DISPLAY PIC 9(02)V9.
03  WS-DISPLAY-X REDEFINES WS-DISPLAY PIC X(03).

MOVE X'FF' TO WS-HEX-BYTE.
MOVE ZERO TO WS-PACKED.
MOVE WS-HEX-BYTE TO WS-PACKED-X (1:1).
MOVE WS-PACKED-V9 TO WS-DISPLAY-V9.
INSPECT WS-DISPLAY-X CONVERTING X'FAFBFCFDFEFF' TO 'ABCDEF'.

In this example and after the INSPECT, WS-DISPLAY-X (1:2) will equal C'FF'. Byte three will always equal C'0'.

(I know Jack's going to get after me about this) icon_wink.gif

HTH....

Regards,

Bill
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Sat Jan 17, 2009 5:49 am    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

Yes, set up an array of 2-byte entries with values from '00' to 'FF'.

Use the byte with the hex-value as the displacement into the array and you have the value for any possible one-byte hex-value.


Dick,

Assuming that a WS binary-halfword is first cleared to H'0' and then a 2-byte redefinition of PIC XX is defined over this halfword, the hex-value is moved to the 2nd-Byte. Then the halfword needs to be bumped by 01, because the table would have 256-entries (C'00' through C'FF', beginning with entry 01).

Regards,

Bill
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jan 17, 2009 7:28 am    Post subject:
Reply with quote

Hi Bill,

Quote:
. . .Then the halfword needs to be bumped by 01. . .

Yup, this has been working for longer than i prefer to admit. . . If i've not messed up the copy/paste, it is a bit of callable code that will return the hex over/under for a string of up to 2000 bytes. The calling code provides the number of bytes and the string to be converted to hex.

Code:

      *---------------------------------------------------------------*
      *                                                               *
      * THIS CODE WILL CONVERT AN INPUT STRING TO HEX OVER/UNDER      *
      *  REPRESENTATION FOR DEBUGGING/READABILITY.                    *
      *                                                               *
      *---------------------------------------------------------------*

       77  WKN                 PIC 9(5) COMP.                           
      *                                                                 
       01  HEX-VALUES.                                                 
           05 FILLER PIC X(32) VALUE '000102030405060708090A0B0C0D0E0F'.
           05 FILLER PIC X(32) VALUE '101112131415161718191A1B1C1D1E1F'.
           05 FILLER PIC X(32) VALUE '202122232425262728292A2B2C2D2E2F'.
           05 FILLER PIC X(32) VALUE '303132333435363738393A3B3C3D3E3F'.
           05 FILLER PIC X(32) VALUE '404142434445464748494A4B4C4D4E4F'.
           05 FILLER PIC X(32) VALUE '505152535455565758595A5B5C5D5E5F'.
           05 FILLER PIC X(32) VALUE '606162636465666768696A6B6C6D6E6F'.
           05 FILLER PIC X(32) VALUE '707172737475767778797A7B7C7D7E7F'.
           05 FILLER PIC X(32) VALUE '808182838485868788898A8B8C8D8E8F'.
           05 FILLER PIC X(32) VALUE '909192939495969798999A9B9C9D9E9F'.
           05 FILLER PIC X(32) VALUE 'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'.
           05 FILLER PIC X(32) VALUE 'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'.
           05 FILLER PIC X(32) VALUE 'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'.
           05 FILLER PIC X(32) VALUE 'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'.
           05 FILLER PIC X(32) VALUE 'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'.
           05 FILLER PIC X(32) VALUE 'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'.
       01  HEX-VALUES-R REDEFINES HEX-VALUES.                           
           05 HEX-CHAR     OCCURS 256 TIMES                             
                           INDEXED BY HX-INX.                           
              10 HEX-OVER  PIC X.                                       
              10 HEX-UNDER PIC X.                                       
      *                                                                 
       01  WORK-CHAR.                                                   
           05 FILLER PIC X.                                             
           05 WC-X   PIC X.                                             
       01  WORK-CHAR-N REDEFINES WORK-CHAR.                             
           05 WC-N   PIC 99 COMP.                                       

       LINKAGE SECTION.                                           
      *                                                           
       01  THE-NUMBER        PIC 9(5) COMP.                       
      *                                                           
       01  ORIGINAL-LINE.                                         
           05 ORIG-CHAR      PIC X OCCURS 2000 TIMES               
                             INDEXED BY ORG-INX.                   
      *                                                           
       01  HEX-OVER-LINE.                                         
           05 HEX-OVER-CHAR  PIC X OCCURS 2000 TIMES               
                             INDEXED BY HO-INX.                   
      *                                                           
       01  HEX-UNDER-LINE.                                         
           05 HEX-UNDER-CHAR PIC X OCCURS 2000 TIMES               
                             INDEXED BY HU-INX.                   
      *                                                           
       PROCEDURE DIVISION USING THE-NUMBER,                       
                                ORIGINAL-LINE,                     
                                HEX-OVER-LINE,                     
                                HEX-UNDER-LINE.                   
      *                                                           
           MOVE LOW-VALUES TO WORK-CHAR.                           
      *                                                           
           PERFORM 050-DUMMY THRU 059-DUMMY-EXIT                   
                             VARYING ORG-INX FROM 1 BY 1           
                             UNTIL ORG-INX > THE-NUMBER.           
           GO TO 999-END.                                         
      *                                                           
       050-DUMMY.                                                 
           MOVE ORIG-CHAR(ORG-INX) TO WC-X.                       
      *    DISPLAY WORK-CHAR ' ' WC-X ' ' WC-N.                   
           COMPUTE WKN = WC-N + 1.                                 
           SET HX-INX TO WKN.                                     
           SET HO-INX TO ORG-INX.                                 
           MOVE HEX-OVER(HX-INX) TO HEX-OVER-CHAR(HO-INX).         
           SET HU-INX TO ORG-INX.                                 
           MOVE HEX-UNDER(HX-INX) TO HEX-UNDER-CHAR(HU-INX).       
      *                                                                     
       059-DUMMY-EXIT.     
           EXIT.           
      *                     
       999-END.             
           GOBACK.         
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts Group Data based on a key Arun Raj DFSORT/ICETOOL 7 Thu Apr 27, 2017 11:29 pm
No new posts unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
No new posts SORT JSON type of data maxsubrat DFSORT/ICETOOL 8 Wed Apr 19, 2017 6:01 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us