C Collection of code snippets by Arne Vajhøj 
C (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
      program main
      call test('1')
      call test('12')
      call test('123')
      end
c
      subroutine test(s)
      character*(*) s
      integer*4 toint, tointx, tointxx
      write(*,'(1x,a,3h : ,i3)') s, toint(s)
      write(*,'(1x,a,3h : ,i3)') s, tointx(s)
      write(*,'(1x,a,3h : ,i3)') s, tointxx(s)
      end
c
      integer*4 function toint(s)
      character*(*) s
      integer*4 res
      read(s,'(i)') res
      toint = res
      end
c
      integer*4 function tointx(s)
      character*(*) s
      integer*4 res, i
      res = 0
      do 100 i = 1, len(s)
        res = 10 * res + (ichar(s(i:i)) - ichar('0'))
100   continue
      tointx = res
      end
c
      integer*4 function tointxx(s)
      character*(*) s
      integer*4 res, i
      res = 0
      do 100 i = 1, len(s)
        res = 10 * res + (ichar(s(i:i)) - 48)
100   continue
      tointxx = res
      end
