FORTRAN has no hex support, this little program shows how to convert
a 16 bit word (integer) to a hex as 4A1 (like CALL PDUMP output) and
convert an 4A1 hex input to an integer. Note: hex just interprets exact as is bits, so has no sign value
// JOB T
// FOR
*LIST ALL
*IOCS(CARD,TYPEWRITER,KEYBOARD,1132 PRINTER)
*ONE WORD INTEGERS
INTEGER HEXC(16),HEXD(16),H(4),ADD
DATA HEXC/'0','1','2','3','4','5','6','7','8','9',
+'A','B','C','D','E','F'/
DATA HEXD/0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15/
CONVERT DECIMAL TO HEX
WRITE(1,1)
1 FORMAT('ENTER A 6 DIGIT INTEGER, MUST USE LEADING ZEROS')
READ(6, 10)I
10 FORMAT(I6)
ADD=0
IF(I)11,14,14
11 I=I+32767+1
ADD=8
14 J=4
15 IF(J)30,30,20
20 K=I-I/16*16+1
IF(J-1)22,21,22
21 K=K+ADD
22 H(J)=HEXC(K)
I=I/16
J=J-1
GO TO 15
30 CONTINUE
WRITE(1, 50)H
50 FORMAT(4A1)
CONVERT BACK FROM HEX TO DECIMAL
COULD ALSO DO A READ OF H AS A 4A1
I=0
J=4
DO 140 N=1,4
100 IF(J)140,140,110
110 DO 120 K=1,16
IF(H(J)-HEXC(K))120,130,120
120 CONTINUE
C NON HEX CHAR IS AN ERROR
I=0
GO TO 150
130 I=I+HEXD(K)*16**(N-1)
J=J-1
140 CONTINUE
150 WRITE(1, 10)I
CALL EXIT
END
// XEQ