# how to convert Hex String t char hex

Author Message
Martylin

New User

Joined: 08 Mar 2016
Posts: 13
Location: Taiwan

 Posted: Fri Jun 05, 2020 7:45 pm If I have a hex string, how to how to convert to a char hex DCL HEX_STRING CHAR(4) INIT('A02F'); DCL CHAR_2B CHAR(2); CHAR_2B would like be A2 0F
Garry Carroll

Senior Member

Joined: 08 May 2006
Posts: 1175
Location: Dublin, Ireland

Posted: Fri Jun 05, 2020 8:14 pm

The description does not make sense.

A hex string A02F would be declared as
 Code: DCL HEX_STRING     CHAR(2) INIT('A02F'X);

and would not be a CHAR(4) string.

What is described as the desired result looks like what would be displayed for the declare statement I've given when in TSO browse/view/edit with HEX ON.

What are you trying to achieve?

Garry.
prino

Senior Member

Joined: 07 Feb 2009
Posts: 1285
Location: Vilnius, Lithuania

Posted: Sat Jun 06, 2020 12:27 am

 Martylin wrote: If I have a hex string, how to how to convert to a char hex DCL HEX_STRING CHAR(4) INIT('A02F'); DCL CHAR_2B CHAR(2); CHAR_2B would like be A2 0F

Why don't you actually RTFM, like experts (this is a forum for experts, you know?) do? PL/I has builtin functions to do this!
Martylin

New User

Joined: 08 Mar 2016
Posts: 13
Location: Taiwan

Posted: Sat Jun 06, 2020 5:42 am

Garry Carroll wrote:
The description does not make sense.

A hex string A02F would be declared as
 Code: DCL HEX_STRING     CHAR(2) INIT('A02F'X);

and would not be a CHAR(4) string.

What is described as the desired result looks like what would be displayed for the declare statement I've given when in TSO browse/view/edit with HEX ON.

What are you trying to achieve?

Garry.

no, I mean if I read a dataset, there are some hex string format, I have to convert to char hex, i don't know how to do it ?

prino

Senior Member

Joined: 07 Feb 2009
Posts: 1285
Location: Vilnius, Lithuania

 Posted: Sat Jun 06, 2020 1:03 pm Maybe you can show os some of those "hex string format lines", by viewing the dataset, giving the command "hex" and cutting and pasting some of the data between {code} {/code} tags (use square brackets!) We do not want to see images!
Martylin

New User

Joined: 08 Mar 2016
Posts: 13
Location: Taiwan

Posted: Mon Jun 08, 2020 1:40 pm

I solved the problem, but I still don't know how to transform hex string to char hex.

my solution is tell the provider (open system), give me the decimal string range will be 0 ~ 65535. The input format is complex, I just pick some fields

 Code: DCL                                                                  1 TB_IN,                      /* FOR TEST ONLY */                    5 GK_ID          CHAR(4)    INIT('ABCD'),                          5 GK_TAB1        CHAR(1)    INIT('05'X),                          5 GK_DEC_STRING  PIC'99999' INIT(16545); /* HEXADECIMAL 40A1 */     /* originall is this  5 GK_HEX_STRING  CHAR(4)  */  DCL                                                                   1 TB_OUT,                                                             5 GK_ID         CHAR(4),                                             5 GK_TAB1       CHAR(1),                                             5 GK_CHARS      CHAR(2);                                                                                                             DCL  GK_BIN   FIXED BIN(31);                                         DCL  GK_BIT   BIT(32);                                               DCL  GK_TEMP  CHAR(4) BASED(ADDR(GK_BIT));                                                                                               GK_BIN  = TB_IN.GK_DEC_STRING;                                             GK_BIT = UNSPEC(GK_BIN);                                                                                                                 TB_OUT.GK_ID    = TB_IN.GK_ID;                                       TB_OUT.GK_TAB1  = TB_IN.GK_TAB1;                                     TB_OUT.GK_CHARS = SUBSTR(GK_TEMP,3,2);                                                                   PUT SKIP LIST('TB_OUT=' || STRING(TB_OUT)); ----+----1----+ *************** TB_OUT=ABCD  ~    EC6DEE7CCCC04A 32D643E1234501

if is GK_HEX_STRING = '40A1';

how to transform like:

 Code: ----+----1----+ ***************  ~    4A 01
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 1612

Posted: Mon Jun 08, 2020 5:15 pm

 Martylin wrote: I solved the problem, but I still don't know how to transform hex string to char hex.

1) Do you speak English?

2) Do you know what Google.com is?

3) Do you have a computer?

4) Are you able to use Internet?

 Quote: HEX(x) HEX returns a character string that is the hexadecimal representation of the storage that contains x.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Need to find a specific STRING COBOL Programming 11 String has hex character need to conv... COBOL Programming 3 SORT - To repeat a string in same col... SYNCSORT 3 JCL - To repeat a string in same colu... JCL & VSAM 2 Replace a string in a VB file and cop... DFSORT/ICETOOL 2
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us