20 pts.
 RPG ILE Character Hex Value to Decimal
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?

Software/Hardware used:
ASKED: April 29, 2009  3:36 PM
UPDATED: April 30, 2009  1:02 PM

Answer Wiki:
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
Last Wiki Answer Submitted:  April 30, 2009  1:02 pm  by  philpl1jb   44,190 pts.
All Answer Wiki Contributors:  philpl1jb   44,190 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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 pts.