Converting ASCCI to Hex value


My input fild has ASCCI value (say 75), My requirement is to convert this to Hex value and write to a outout work file (This should be ‘4B’ for input value of 70).

How do I do this ASCCI to hexadecimal conversion in Natural. Is there any Natural function available for this.

I need this information urgently.


ASCII to Hexadecimal conversion works like this:

move edited #a-field1 (EM=HHHH) to #a-field2

But I guess you mean decimal to hexadecimal conversion…
And this is done the following way:

define data local
01 #decimal     (B2)
01 #hexadecimal (A4)
#decimal := 75
move edited #decimal (EM=HHHHHHHH) to #hexadecimal
display #hexadecimal

Please note that #byte is a field of type B.

I’m a little confused. 70 would be X’46’. Do you want to convert the ASCII character to the EBCDIC equivalent in hex?

If so, look in the NATURAL Library SYSEXT. There is a subprogram that will convert ASCII characters to EBCDIC characters. Sorry, but I don’t remember which USR module it is and I don’t have access to NATURAL today.

The initial questions said “My input fild has ASCCI value (say 75)”, which would be the x’4b’ mentioned later, I assume that’s just a little inconsistency :wink:

It’s USR0620N


Is there any way to convert hexadecimal to it’s equivalent text and to decimal value? Is there any edit mask available for hexa decimal to decimal conversion?


I sometimes use this as an exercise in my classes. Write a subprogram to convert Hex to decimal. Not very hard.

When questions like this are asked, such as how to convert ASCII decimal values to hexadecimal or vice versa on a Natural for Mainframes (implying EBCDIC environment) forum, it would be helpful to understand the business reason driving the requirements to do so. So many integration methods take care of ASCII->EBCDIC and EBCDIC->ASCII conversion, and it is extremely rare that one would ever have to write Natural code to manipulate or convert decimal or hexadecimal values, so understanding the actual need behind the question might actually lead to a more holistic answer than the simple answer to the question provides.

There are cases in which this would be the proper approach, and as Steve mentions, there was really easy ways to render data in different formats. I’m just concerned that it may not be the best approach for the underlying problem.

If this is an interview question, just be upfront about it. Please.

If it is an interview/test type of question, just be upfront about it,.Please.