Tuesday, February 19, 2008

Code Snippet – Convert between Char and Hexadecimal:

H BNDDIR('QC2LE')

D CvtHex1To2 PR ExtProc('CVTHC')
D LongReceiver * Value
D ShortSource * Value
D ReceiverBytes 10I 0 Value

D CvtHex2To1 PR ExtProc('CVTCH')
D shortReceiver * Value
D longSource * Value
D sourceBytes 10I 0 Value

D charval S 4A Inz('1F3D')
D hexval S 5A Inz(X'C1C2C3C4C5')

D charResult S 10A
D intResult S 5I 0

* convert from a character value to an integer

C CallP CvtHex1To2 (%addr(intResult)
C : %addr(charval)
C : %size(intResult) * 2)

* convert from a hex value to an character

C CallP CvtHex2To1 (%addr(charResult)
C : %addr(hexval)
C : %size(charResult))

No comments: