RPG ILE Character Hex Value to Decimal

20 pts.
Tags:
Character
Hexadecimal values
RPG ILE
Hi, I have a flat file with hexidecimal characters after certain characters. For Example : "MY NAME IS BEN ~0A" The "0A" represents the hex for 10 (decimal) whitch means 10 spaces. My problem is when i have "0A" in a alpha numeric workfield (length 2), how can i use it as a hex value? In other words i need to change it to X'0A' in a alpha numeric field length 1 or to 10 in a decimal field. Hardcode will look something like this:
D IntDS           ds                                   
D IntNum                         5i 0 inz(0)           
D IntChar                        1a   Overlay(IntNum:2)

c                   move      X'0A'         IntChar
Now IntNum will contain the value 10. Now all i have is a workfield with the character value "0A". How do i get to 10?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Here’s a site with solution

http://faq.midrange.com/data/cache/114.html

Which translates for your request to something like this

H bnddir(‘QC2LE’)
D cvthex2To1 PR extproc(‘cvtch’)
D shortReceiver * value
D longSource * value
D sourceBytes 10i 0 value

D charval S 2a inz(‘0A’)
D intResult S 3i 0

* convert from a character value ‘1F3D’ to an integer
C callp cvthex2To1 (%addr(intResult)
C : %addr(charval)
C : %size(intResult) * 2)
C intResult dsply
C eval *inlr = *on
C return
Where charVal is your extracted value and intResult is the converted value.

Good Luck
Phil
//////////////////////////////////////

Thanks for the feedback Stefan.

Right – you had a 2byte hex – charval 2a
16^2 = 256
That will produce a 3i 0 intResult. (0 – 256)

Phil

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Oupablok
    Thanks Phil, It works perfect. All day yesterday I was trying this exact same example but was constantly getting a Domain error. For future reference I think I was doing something wrong with the length of my work fields. Thanks again, Stefan
    20 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following