2006 May 05 12:29 PM
Hallo everyone,
I want to get the hex value from a string or a character,is there any way to do it?
for example,
I have a character '1',
how can I get the hex value of it,which value is it?
I tried many methods but no succeess...
thanks in advance.
Liying Wang
Message was edited by: Liying Wang
2006 May 05 12:42 PM
Hi Liying,
Try this FM:
NLS_STRING_CONVERT_FROM_SYS
and for vice versa,
try this NLS_STRING_CONVERT_TO_SYS
Regards,
Ravi
2006 May 05 12:41 PM
REPORT ZC1_NUMBER_CONVERSION .
data: v_hexa type x,
v_deci type i.
v_deci = '192'.
v_hexa = v_deci.
write:/ 'Decimal :' , v_deci , ' = Hexa Decimal :' , v_hexa.
I got the following result,
Number Conversion
Decimal : 192 = Hexa Decimal : C0
for char to hex..use
Try function module CHAR_HEX_CONVERSION.
2006 May 05 1:13 PM
Thanks for ur post,
but I got the runtime error when I call this fm.
my code:
DATA: hexstring type x,
hexint type i.
hexint = '1'.
call function 'CHAR_HEX_CONVERSION'
exporting
input = hexint
importing
hexstring = hexstring.
what was wrong?
2006 May 05 1:18 PM
declare hexstring as normal char type variable.
<b>DATA: hexstring(2) type c.</b>
Regards,
Ravi
2006 May 05 1:38 PM
Thanks Ravi,
your solution with FM 'NLS_STRING_CONVERT_FROM_SYS' works.
btw I used DATA: hexstring(2) type c.
but I still got the runtime error
anyway I solved the problem,thanks!
Liying
2006 May 08 3:20 PM
Once again one question:
what is the string symbol for hex value 'A0'
thanks for feedback!
Liying
2006 May 05 12:42 PM
Hi Liying,
Try this FM:
NLS_STRING_CONVERT_FROM_SYS
and for vice versa,
try this NLS_STRING_CONVERT_TO_SYS
Regards,
Ravi
2006 May 05 12:43 PM
HI
GOOD
Hexadecimal Literals
A hexadecimal literal is specified within single quotes as if it were a character string. The permissible values are 0-9 and A-F. There must be an even number of characters in the string, and all characters must be in uppercase.
CAUTION
If you specify a hexadecimal literal using lowercase characters, you will not receive any warnings or errors. However, when your program runs, the value of the literal will be wrong.
Examples of valid hexadecimal literals are '00', 'A2E5', and 'F1F0FF'. Examples of invalid hexadecimal literals are 'a2e5' (contains lowercase characters), '0' (contains an uneven number of characters), "FF" (enclosed in double quotes), and x'00' (should not have a preceding x).
NOTE
Hexadecimal values are rarely used in ABAP/4, because they are usually machine-dependent. The use of a hexadecimal value that creates machine dependence should be avoided.
DATA: HEX(1) TYPE X VALUE 'B5',
B(1) TYPE N.
DO 8 TIMES.
GET BIT SY-INDEX OF HEX INTO B.
WRITE B NO-GAP.
ENDDO.
THANKS
MRUTYUN
Message was edited by: Mrutyunjaya Tripathy
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |