× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Hex Values of a Character field
  • From: "Simon Coulter" <shc@xxxxxxxxxxxxxxxxx>
  • Date: Fri, 27 Mar 98 07:05:34 +1100

Hello Joe,

Here is a way for non-ILE RPG.

Given the following array definitions (you can change the size of C78 to handle 
different size 
strings to convert).  Note that I am converting each hex digit into a separate 
array so I can 
show an over/under hexadecimal display.  You could easily alter this to convert 
the characters 
to a side-by-side representation.  The basic premise is:  since each nybble 
(4-bits) is to be 
converted to its hex value we need to extract each nybble; since the maximum 
value a nybble can 
contain is x'F' or decimal 16 we can divide each character by 16 to extract the 
most 
significant (left-most) nybble and use the remainder for the least significant 
(right-most) 
nybble.

     ‚/TITLE    SHWFMCR      : Show File Member Contents
     ‚*-------------------------------------------------------------------
     ‚* A R R A Y   D E C L A R A T I O N S
     ‚*-------------------------------------------------------------------
     E                    C78        78  1               ‚HEX array - IN
     E                    HEX1       78  1               ‚HEX array - OUT
     E                    HEX2       78  1               ‚HEX array - OUT
     E                    HEXDGT 16  16  1               ‚HEX conversion array

     ‚/TITLE    SHWFMCR      : Show File Member Contents
     ‚*-------------------------------------------------------------------
     ‚* D A T A   S T R U C T U R E   D E C L A R A T I O N S
     ‚*-------------------------------------------------------------------
     ‚* Miscellaneous declares that need to be binary values
     IMISC        DS
     I                                    B   1   20BIN
     I                                        2   2 CBIN

     ‚* Copy the data to convert to hex                                        *
     C                     MOVEADATA,WDW  C78              ‚
<--- C                     EXSR CVTHEX                     ‚Convert to hex

     ‚/TITLE    SHWFMCR      : Show File Member Contents - CVTHEX
     ‚*** Start of specifications **********************************************
     ‚*                                                                        *
     ‚* Subroutine name . . . . . : CVTHEX                                     *
     ‚*                                                                        *
     ‚* Descriptive name  . . . . : Convert to hexadecimal                     *
     ‚*                                                                        *
     ‚* Function  . . . . . . . . : To convert a value to hexadecimal display  *
     ‚*                             format.                                    *
     ‚*                                                                        *
     ‚* Input . . . . . . . . . . : C78 - Character string                     *
     ‚*                                                                        *
     ‚* Output  . . . . . . . . . : HEX1 - Top row of hex characters           *
     ‚*                             HEX2 - Bottom row of hex characters        *
     ‚*                                                                        *
     ‚* Exits-- Normal  . . . . . : Return to NSI                              *
     ‚*      -- Error . . . . . . :                                            *
     ‚*                                                                        *
     ‚*** End of specifications ************************************************
---> CSR         CVTHEX    BEGSR                           ‚
     ‚*          ------
     C                     Z-ADD*ZERO     BIN              ‚
     C                     Z-ADD*ZERO     O       50       ‚OUT counter
B1   C           1         DO   78        I                ‚IN counter
     C                     MOVE C78,I     CBIN             ‚Make binary
     C           BIN       DIV  16        HI      30       ‚High order nybble
     C                     MVR            LO      30       ‚Low order  nybble
     C                     ADD  1         HI   H           ‚Round up for HEXDGT
     C                     ADD  1         LO               ‚Round up for HEXDGT
     C                     ADD  1         O                ‚Increment OUT counte
     C                     MOVE HEXDGT,HI HEX1,O           ‚Convert high order
     C                     MOVE HEXDGT,LO HEX2,O           ‚Convert low order
E1   C                     END                             ‚1 DO 78
     ‚*
<--- CSR                   ENDSR                           ‚CVTHEX
     ‚*===================================================================
     ‚* A R R A Y   I N I T I A L I S A T I O N
     ‚*===================================================================
**  Hex conversion - HEXDGT - 16-bytes
0123456789ABCDEF
 

Regards,
Simon Coulter.

//----------------------------------------------------------
// FlyByNight Software         AS/400 Technical Specialists
// Phone: +61 3 9419 0175      Mobile: +61 3 0411 091 400
// Fax:   +61 3 9419 0175      E-mail: shc@flybynight.com.au
// 
// Windoze should not be open at Warp speed.
 

+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.