When communicating with ASCII computers through the async workstation controller of our AS/400, I sometimes need to convert a decimal number to its equivalent hexadecimal value. I wrote a short RPG program (HEX001RG) to handle the conversion, as illustrated in 2.
When communicating with ASCII computers through the async workstation controller of our AS/400, I sometimes need to convert a decimal number to its equivalent hexadecimal value. I wrote a short RPG program (HEX001RG) to handle the conversion, as illustrated in Figure 2.
The program accepts a 15-digit, right-justified decimal integer through a character variable. It returns the equivalent hexadecimal value in another 15- character variable. This program is meant to be called from another program that requires the conversion. For example, you could write a display file and program to accept a decimal integer and display the converted value.
Decimal-to-Hex Conversion Program
Figure 2 Decimal-to-Hex Conversion Program HEX001RG
*=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/HEX001RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 E HX 15 15 1 * C *ENTRY PLIST C PARM PDEC 15 C PARM $HEX * C MOVE PDEC $DEC 150 C MOVE *BLANKS $HEX C $DEC IFNE 0 C EXSR CALC C EXSR SWAP C ELSE C MOVE $DEC $HEX C ENDIF C MOVE *ON *INLR ***************************************************************** C CALC BEGSR * C $DEC DOWGE16 C $DEC DIV 16 $DEC C MVR X C X IFGT 0 C $HEX CAT HX,X:0 $HEX C ELSE C $HEX CAT '0':0 $HEX C ENDIF C ENDDO * C Z-ADD$DEC X 30 C $HEX CAT HX,X:0 $HEX 15 P C ENDSR ***************************************************************** C SWAP BEGSR * C ' ' CHEKR$HEX Z 30 C Z DOWGT0 C SUBST$HEX:Z $CHR1 1 P C $HLD CAT $CHR1:0 $HLD 15 P C SUB 1 Z C ENDDO * C MOVE *BLANKS $HEX C ' ' CHEKR$HLD Z C 15 SUB Z Z * C Z DOWGT0 C $HEX CAT '0':0 $HEX C SUB 1 Z C ENDDO * C $HEX CAT $HLD:0 $HEX C ENDSR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ** HX 123456789ABCDEF
LATEST COMMENTS
MC Press Online