# Converting ASCCI to Hex value

**URL:** <https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [August 4, 2006, 3:05pm UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283 "2006-08-04T15:05:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimut](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jimut](https://techcommunity.softwareag.com/u/jimut)\
**Post date:** [August 4, 2006, 3:05pm UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/1 "2006-08-04T15:05:35Z")

</div>

Hi,

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.

Regards,  
Jimut.

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 4, 2006, 3:33pm UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/2 "2006-08-04T15:33:46Z")

</div>

ASCII to Hexadecimal conversion works like this:

```auto
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:

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

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

---

<div class="post-metadata">

**Author:** ![Wayne\_Campos](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wayne_campos/32/104_2.png) [@Wayne\_Campos](https://techcommunity.softwareag.com/u/Wayne_Campos)\
**Post date:** [August 7, 2006, 2:17am UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/3 "2006-08-07T02:17:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [August 7, 2006, 3:10am UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/4 "2006-08-07T03:10:45Z")

</div>

> [@Wayne Campos](#):
>
> I’m a little confused. 70 would be X’46’. Do you want to convert the ASCII character to the EBCDIC equivalent in hex?

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 😉

> [@Wayne Campos](#):
>
> 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.

It’s USR0620N

---

<div class="post-metadata">

**Author:** ![krishna\_prasad2](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@krishna\_prasad2](https://techcommunity.softwareag.com/u/krishna_prasad2)\
**Post date:** [April 21, 2016, 6:08am UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/5 "2016-04-21T06:08:02Z")

</div>

Hello

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?

Regards  
Krishna

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [April 21, 2016, 4:31pm UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/6 "2016-04-21T16:31:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Johnson1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/brian_johnson1/32/163_2.png) [@Brian\_Johnson1](https://techcommunity.softwareag.com/u/Brian_Johnson1)\
**Post date:** [April 22, 2016, 2:33pm UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/7 "2016-04-22T14:33:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [April 23, 2016, 9:59am UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/8 "2016-04-23T09:59:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [April 23, 2016, 10:04am UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/9 "2016-04-23T10:04:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:40pm UTC](https://techcommunity.softwareag.com/t/converting-ascci-to-hex-value/61283/10 "2021-04-02T14:40:46Z")

</div>


