Blog Archive

RPGLE convert character to hexadecimal equivalent

Using the C runtime MI functions Convert Character to Hex (CVTHC) provides another method for such conversion in RPGLE. You need to use the C binding directory QC2LE. It converts a each character value in the string to a two-byte value of hex digits.

Prototyping C function cvthc in RPGLE
H DftActGrp(*NO) Option(*SRCSTMT)             
H bnddir('QC2LE')            

D CharToHex       PR                  ExtProc( 'cvthc' )            
D  CTHHex                         *   value                         
D  CTHChar                        *   value                         
D  CTHCharSize                  10I 0 value                         
                                                                    
D charval         S             26a   inz('ATEST123')               
D hexval          S             52a                                 

C                   callp     CharToHex (%addr(hexval)          
C                                       : %addr(charval)        
C                                       : %size(hexval)) 

Complete source Code for Testing. You can put in debug and check.
H DftActGrp(*NO) Option(*SRCSTMT)                                      
H bnddir('QC2LE')                                                      
                                                                       
D HexToChar       PR                  ExtProc('cvtch')                 
D  HTCChar                        *   value                            
D  HTCHex                         *   value                            
D  HTCCharSize                  10I 0 value                            
                                                                       
D CharToHex       PR                  ExtProc( 'cvthc' )               
D  CTHHex                         *   value                            
D  CTHChar                        *   value                            
D  CTHCharSize                  10I 0 value                            
                                                                       
D charval         S             26a   inz('ATEST123')                  
D hexval          S             52a                                    
                                                                       
C                   callp     CharToHex (%addr(hexval)                 
C                                       : %addr(charval)               
C                                       : %size(hexval))               
                                                                       
C     charval       dsply                                              
C     hexval        dsply                                              

                                                                     
C                   callp     HexToChar (%addr(charval)              
C                                       : %addr(hexval)              
C                                       : %size(charval)*2)          
                                                                     
C     charval       dsply                                            
C     hexval        dsply                                            
                                                                     
C                   eval      *inlr = *on         

Recommended Reading


6 comments :

  1. Awsome! it works as advertised...Thanks so much!

    ReplyDelete
  2. it doesn't works : error is

    Informazioni aggiuntive sul messaggio

    ID messaggio . . . . . : C2M3001
    Data di invio . . . . : 22/01/14 Ora di invio . . . . . : 10:24:13

    Messaggio . . . : Si è verificato un errore di dominio nella funzione
    matematica.

    Causa . . . : Un argomento di immissione è al di fuori del dominio per il
    quale è stata definita la funzione matematica.
    Correzione . . . : Fornire valori di immissioni coerenti con la definizione
    matematica della funzione.
    Descrizione tecnica . . . . . . . : Il valore 'errno' è impostato su EDOM

    the sources has been compiled by option 14 in STRPDM

    ReplyDelete
  3. Works fine for me. Thanks for the great examples.

    ReplyDelete
  4. If you are fond of watching movies and tired of waiting to buffer, then you must use Moviebox app, which is one such app that allows you to stream movies

    on your smart devices without having to wait for buffering. Also it is absolutely free and really easy to install. For more info about how to install it, just

    follow the link here Moviebox for PC

    ReplyDelete
  5. Very important article for JAVA. I found this article best resources of JAVA. For more details here this site

    ReplyDelete