PDA

View Full Version : [LF] Integer to hexadecimal


Lahey Support
08-15-2003, 01:19 AM
Here is a Fortran77 routine for doing integer*2 to hex efficiently.
Just convert to Fortran 90 usage. Repeat if using integer*4.
Normally CSTAT(4) is also redefined as a 4-character string for reporting
ease.

T.B.Wright

SUBROUTINE KSTAT(ISTAT,CSTAT)
C converts Integer ISTAT to 4 byte character hexadecimal string
IMPLICIT INTEGER*2 (I-N)
CHARACTER CSTAT(4),CL,CH,CX,CLH(2),CHAR(16)
INTEGER*2 ISTAT,ICLH,ICX
EQUIVALENCE (CL,CLH(1),ICLH),(CH,CLH(2))
EQUIVALENCE (CX,ICX)
DATA CHAR/'0','1','2','3','4','5','6','7',
1 '8','9','A','B','C','D','E','F'/
ICX=0
ICLH=ISTAT
CX=CH
K1=ICX/16
K2=ICX-(K1*16)+1
K1=K1+1
CX=CL
K3=ICX/16
K4=ICX-(K3*16)+1
K3=K3+1
CSTAT(1)=CHAR(K1)
CSTAT(2)=CHAR(K2)
CSTAT(3)=CHAR(K3)
CSTAT(4)=CHAR(K4)
RETURN
END