Have a MACRO laying around here...

         MACRO                                                         
&LABEL   HX2CH &FLD,&REG                                               
.* CONVERTS THE HEX FIELD IN '&FLD' WHOSE LENGTH                       
.* IS IN REGISTER '&REG' TO CHARACTER INTO '&FLD'                      
.* '&FLD' MUST BE BIG ENOUGH TO HOLD THE CHARACTER VERSION OF THE      
.* HEX NUMBER THAT IS BEING CONVERTED (I.E. TWICE THE LENGTH IN '&REG')
                    AIF   (&REG GT 1 AND &REG LT 15).OK                         
  
                    MNOTE 12,'USE ONLY REGS 2 TO 14 FOR SECOND OPERAND'         
  
                    MEXIT                                                       
  
.OK            ANOP                                                          
&LABEL     LR    1,&REG              R1 = LENGTH OF HEX FIELD            
                   BCTR  1,0                 ADJUST TO USE AS INDEX             
 
                   LA    15,&FLD.(1)         R15 -> LAST BYTE OF HEX FLD        
 
                  AR    1,1                 DOUBLE TO INDEX CHAR FIELD          
                  LA    1,&FLD.(1)          R1 -> LAST 2 BYTES OF CHAR FLD      
                  LR    0,&REG              R0 = # OF HEX BYTES TO BE CONVERTED 
A&SYSNDX MVC   1(1,1),0(15)                                            
                       UNPK  0(1,1),0(1,15)                                     
     
                       NI    0(1),X'0F'             
                       NI    1(1),X'0F'             
                      BCTR  15,0                   
                      BCTR  1,0                    
                      BCTR  1,0                    
                     BCT   0,A&SYSNDX             
                     LR    15,&REG                
                     AR    15,15                  
                     BCTR  15,0                   
                     EX    15,B&SYSNDX            
                     B     C&SYSNDX+16            
B&SYSNDX TR    &FLD.(0),C&SYSNDX      
C&SYSNDX DC    C'0123456789ABCDEF'    
                      MEND                         

Jay Campbell
IBM OS Support Section

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@listserv.ua.edu] On Behalf 
Of Randy Hudson
Sent: Monday, September 12, 2016 12:59 PM
To: IBM-MAIN@listserv.ua.edu
Subject: Re: Converson of hex value to character

In article <CAPtSOKzBLsKuU0=dJLCJ_M8qhBMB0mU_ueirHUM1OBD=f6g...@mail.gmail.com>,
Billy Ashton wrote:

> How do I take a 1-byte character field containing a Hex value like x'C4'
> and turn it into a 2-byte character field containing C4 (x'C3F4')? I 
> know how to turn it into a decimal value and Edit and all that, but I 
> am blanking on this simple conversion.

One way is with three TR instructions, and some MVC instructions.  One TR 
instruction translates each character into the EBCDIC representation of the 
first half, one TR instruction converts each to the EBCDIC representation of 
the second half, and one interleaves them.  Up to 128 bytes of input can be 
handled per pass through this sequence.

Another way uses the UNPK command (from a source which includes a dummy byte in 
the next byte of storage) followed by a single TR instruction.  That uses less 
storage but is limited to 7 bytes of input per pass.

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions, send email to 
lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to