Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How can I get hex value

Former Member
0 Likes
9,908

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,733

Hi Liying,

Try this FM:

NLS_STRING_CONVERT_FROM_SYS

and for vice versa,

try this NLS_STRING_CONVERT_TO_SYS

Regards,

Ravi

7 REPLIES 7
Read only

Former Member
0 Likes
5,733

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.

Read only

0 Likes
5,733

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?

Read only

0 Likes
5,733

declare hexstring as normal char type variable.

<b>DATA: hexstring(2) type c.</b>

Regards,

Ravi

Read only

0 Likes
5,733

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

Read only

0 Likes
5,733

Once again one question:

what is the string symbol for hex value 'A0'

thanks for feedback!

Liying

Read only

Former Member
0 Likes
5,734

Hi Liying,

Try this FM:

NLS_STRING_CONVERT_FROM_SYS

and for vice versa,

try this NLS_STRING_CONVERT_TO_SYS

Regards,

Ravi

Read only

Former Member
0 Likes
5,733

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