IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to convert Hex String t char hex


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Martylin

New User


Joined: 08 Mar 2016
Posts: 13
Location: Taiwan

PostPosted: Fri Jun 05, 2020 7:45 pm
Reply with quote

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
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


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

PostPosted: Fri Jun 05, 2020 8:14 pm
Reply with quote

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.
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Sat Jun 06, 2020 12:27 am
Reply with quote

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!
Back to top
View user's profile Send private message
Martylin

New User


Joined: 08 Mar 2016
Posts: 13
Location: Taiwan

PostPosted: Sat Jun 06, 2020 5:42 am
Reply with quote

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 ?
 
 
Back to top
View user's profile Send private message
prino

Senior Member


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

PostPosted: Sat Jun 06, 2020 1:03 pm
Reply with quote

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!
Back to top
View user's profile Send private message
Martylin

New User


Joined: 08 Mar 2016
Posts: 13
Location: Taiwan

PostPosted: Mon Jun 08, 2020 1:40 pm
Reply with quote

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
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2017
Location: USA

PostPosted: Mon Jun 08, 2020 5:15 pm
Reply with quote

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Need to convert date format DFSORT/ICETOOL 20
Search our Forums:

Back to Top