      SUBROUTINE HEX(IOCT,IHEX) 
C SUBROUTINE TO CONVERT BINARY TO ASCII HEX.
C WHERE:
C
C       IOCT= BINARY INTEGER PASSED TO SUBROUTINE.
C       IHEX= 2 WORD ARRAY TO RETURN ASCII HEX VALUE IN.
C            IHEX(1) STORES DIGITS 2,1
C            IHEX(2) STORES DIGITS 4,3   WHERE DIGIT 1 IS MSB.
C
C FURTHER DOCUMENTATION ADDED--16-JAN-80, G. BEVER.
C
C
C FILED BY GLENN BEVER--21-FEB-79.
C          NASA DFRC
C          P.O. BOX 273
C          EDWARDS, CA   93523
C
C COMPILE AS FOLLOWS:
C
C  .R FORTRA
C  *HEX=HEX/U
C
      DIMENSION IB(2),IHEX(2) 
C 'DO 40' LOOP FIGURES 2 ASCII HEX DIGITS FOR EACH OF 2 BINARY BYTES.
      DO 40 J=1,2
C SWAP BYTES.
      IOCT=IRAM(IOCT,8,"177777)
C SPLIT UP BINARY BYTE INTO TWO 4 BIT FIELDS. 
      IB(1)=IRAM(IOCT,4,"17)
      IB(2)=IAND(IOCT,"17)
C 'DO 20' LOOP ADDS APPROP. CONSTANTS TO CONVERT BINARY 
C  HEX TO ASCII HEX.
      DO 20 I=1,2 
      IF(IB(I).GT.9) GO TO 15 
C 0-9.
      IB(I)=IB(I)+"60 
      GO TO 20
C A-F.
   15 IB(I)=IB(I)+"67 
   20 CONTINUE
C MERGE THE TWO ASCII HEX DIGITS INTO ONE WORD.
   40 IHEX(J)=IOR(IB(1),IRAM(IB(2),-8,"177400))
 9999 RETURN
      END
