View previous topic :: View next topic
|
Author |
Message |
Martylin
New User
Joined: 08 Mar 2016 Posts: 13 Location: Taiwan
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
Martylin
New User
Joined: 08 Mar 2016 Posts: 13 Location: Taiwan
|
|
|
|
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
Martylin
New User
Joined: 08 Mar 2016 Posts: 13 Location: Taiwan
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2024 Location: USA
|
|
|
|
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 |
|
|
|