subroutine convert(is,a) c john belcher 2/4/2023 c c convert IBM 360 float to in IEEE 754 c https://en.wikipedia.org/wiki/IBM_hexadecimal_floating-point c c given the 32 bits from the binary tape, convert to IEEE 754 c dimension is(32),g(6) c get sign from first bit sign = +1 if(is(1).ne.0) sign = -1. c get exponent from bits 2 through 8 IE=is(8)+is(7)*2+is(6)*4+is(5)*8+is(4)*16+is(3)*32 IE=IE+is(2)*64 E = IE c write(6,777) E 777 format('E',f20.12) E=(16.)**(E-64.) c write(6,777) E c get significand do 10 i = 1,6 istart = 32 - 4*i +1 ig= i call hex(is(istart),g(ig)) 10 continue ficand=g(6)*(16.**5)+g(5)*(16.**4)+g(4)*(16.**3) ficand = ficand + g(3)*(16.**2)+g(2)*(16.)+g(1) c write(6,888) ficand 888 format('ficand',f30.12) conf = alog(ficand)/alog(16.) iconf = conf + 1. c write(6,555) conf,iconf 555 format('iconf',f10.4,i20) ficand = ficand/(16.**iconf) c write(6,888) ficand c calculate number a = sign*E*ficand return end subroutine hex(ig,f) dimension ig(4) f = ig(1)*8+ig(2)*4+ig(3)*2+ig(4) c write(6,99) ig,f 99 format(4i5,F20.12) return end subroutine getbits(c,i8) c c is a byte, we want to return the 8 bits that c consists of dimension i8(8) character*1 c,f integer I1,I2 character*1 d(4) equivalence (I1,d(1)) f = c I1 = 0 d(1) = f I2 = I1 c write(6,78) I1,c 78 format("getbit",2z16) c i8(8) = mod(I2,2) I2=I2/2 i8(7) = mod(I2,2) I2 = I2/2 i8(6) = mod(I2,2) I2=I2/2 i8(5) = mod(I2,2) I2=I2/2 i8(4) = mod(I2,2) I2 = I2/2 i8(3) = mod(I2,2) I2=I2/2 i8(2) = mod(I2,2) I2=I2/2 i8(1) = mod(I2,2) return end subroutine getmorebits(i,i32) c i is a positve integer c we want to return the 32 bits that i consists of dimension i32(32) integer I2 write(6,78) I 78 format("getmorebits",i32) c i2 = i do 10 j=1,32 k = 32 -j +1 i32(k)=mod(I2,2) I2=I2/2 10 continue write(6,8888) i32 8888 format(" ",8i1," ",8i1," ",8i1," ",8i1) return end