View previous topic :: View next topic |
Author |
Message |
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Mon Jul 08, 2024 7:25 am Post subject: Converting hex values to decimal |
|
|
This seems strange to me and I must be missing something that's ridiculously simple, but for the life of me, I can't find it.
Code: |
select hex(24) from sysibm.sysdummy1 ;
|
shows the hex value 18 as I would expect.
But how do I do the reverse, ie, take the value 18 (assumed to be hex) and convert it to decimal (24).
I'll keep on testing, experimenting, but so far I haven't got anything to work. _________________ Michael |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Thu Jul 11, 2024 12:03 am Post subject: |
|
|
I didn't forget, but maybe you misunderstood my question?
The original post and this one can be simply illustrated with the following Rexx script.
Code: |
str_b = 'F1F2F3'
say str_b' 'x2c(str_b)
str_b = '0018'
say str_b' 'x2d(str_b)
|
with the results being shown as
Quote: |
F1F2F3 123
0018 24
|
The original post was a question on, basically, how to perform the equivalent of Rexx's X2C, whereas this one is how to perform the equivalent of Rexx's X2D. _________________ Michael |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Thu Jul 11, 2024 11:30 am Post subject: |
|
|
misi01 wrote: | I didn't forget, but maybe you misunderstood my question?
|
Misi01,
I did not misunderstand your question. First off you did not mention about replicating the REXX functions as you merely asked for "Converting Hex values to decimal" quoting the example of "select hex(24)"
Now your example Hex value of Decimal 123 is X'7B' and binary bits it is 01111011
Code: |
SELECT HEX(24) AS HEXVALUE_1
,HEX(123) AS HEXVALUE_2
FROM SYSIBM.SYSDUMMY1;
---------+---------+---------+--
HEXVALUE_1 HEXVALUE_2
---------+---------+---------+--
00000018 0000007B
|
So the SQL that I showed converts X'7B' to 123 and X'18' to 24 but however, X'F1F2F3' results in a decimal of 15856371 which is NOT what you want.
Your need to convert character HEX data to decimal doesn't translate the same way.
Run the SQL shown in that post with X'0000007B' and X'00000018' and you will get the result as 123 and 24 respectively. _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
|
|