|
Joe, A very simple way of achieving this would be to overlay your character over the last byte of a 2 byte binary field, which is initialised to zero, in a data structure. Divide the binary field by 16 to get your left nibble. Use the remainder for your right nibble. Then use the lookup method you already employ to convert to a hex character. Or simpler still, just use an array of '0123456789ABCDEF' but add 1 to your index prior to access, this should be quicker than the lookup method. Hope that helps, Tony Smithurst ---------- > From: Joe Giusto <JDG@patuxent.com> > To: 'midrange-l@midrange.com'; 'RPG400-L@midrange.com' > Subject: Hex Values of a Character field > Date: 23 March 1998 07:53 > > does anyone know of a better way to get the hexadecimal value of a > character > field besides the following method: (which i was forced to come up with > for lack of knowing a better way.) > > thanks in advance > > *--------------------------------------------------------------------- > > D TABNUM S 2 0 DIM(15) CTDATA PERRCD(1) > > D TABHEX S 1 DIM(15) ALT(TABNUM) > > *--------------------------------------------------------------------- > > C GET_HEX_VALUE BEGSR > > *--------------------------------------------------------------------* > > * THIS SUBROUTINE WILL ACCEPT A 1 POSITION CHARACTER FLD ##CHARACTER * > > * AND RETURN A TWO CHARACTER FLD ##HEXNUM CONTAINING THE HEXADECIMAL * > > * REPRESENTATION OF ##CHARACTER * > > *--------------------------------------------------------------------* > > C MOVE ##CHARACTER ##CHARACTER 1 > > C Z-ADD 0 ##NUMBER1 2 0 > > C Z-ADD 0 ##NUMBER2 2 0 > > C MOVE *BLANKS ##HEXNUM 2 > > *--------------------------------------------------------------------- > > C TESTB '0' ##CHARACTER 99 > > > > C IF *IN99 > > C ADD 8 ##NUMBER1 > > C ENDIF > > C TESTB '1' ##CHARACTER 99 > > C IF *IN99 > > C ADD 4 ##NUMBER1 > > C ENDIF > > C TESTB '2' ##CHARACTER 99 > > C IF *IN99 > > C ADD 2 ##NUMBER1 > > C ENDIF > > C TESTB '3' ##CHARACTER 99 > > C IF *IN99 > > C ADD 1 ##NUMBER1 > > C ENDIF > > C TESTB '4' ##CHARACTER 99 > > > > C IF *IN99 > > C ADD 8 ##NUMBER2 > > C ENDIF > > C TESTB '5' ##CHARACTER 99 > > C IF *IN99 > > C ADD 4 ##NUMBER2 > > C ENDIF > > C TESTB '6' ##CHARACTER 99 > > C IF *IN99 > > C ADD 2 ##NUMBER2 > > C ENDIF > > C TESTB '7' ##CHARACTER 99 > > C IF *IN99 > > C ADD 1 ##NUMBER2 > > C ENDIF > > *--------------------------------------------------------------------- > > *--------------------------------------------------------------------- > > C ##NUMBER1 LOOKUP TABNUM TABHEX 99 > > C MOVEL TABHEX ##HEXNUM 2 > > C ##NUMBER2 LOOKUP TABNUM TABHEX 99 > > C MOVE TABHEX ##HEXNUM 2 > > *--------------------------------------------------------------------- > > C ENDSR > > ** NUMBER TO HEX CONVERSION TABLE > 011 > 022 > 033 > 044 > 055 > 066 > 077 > 088 > 099 > 10A > 11B > 12C > 13D > 14E > 15F > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > * This is the RPG/400 Discussion Mailing List! To submit a new * > * message, send your mail to "RPG400-L@midrange.com". To unsubscribe * > * from this list send email to MAJORDOMO@midrange.com and specify * > * 'unsubscribe RPG400-L' in the body of your message. Questions should * > * be directed to the list owner / operator: david@midrange.com * > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This is the RPG/400 Discussion Mailing List! To submit a new * * message, send your mail to "RPG400-L@midrange.com". To unsubscribe * * from this list send email to MAJORDOMO@midrange.com and specify * * 'unsubscribe RPG400-L' in the body of your message. Questions should * * be directed to the list owner / operator: david@midrange.com * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.