program hextodec
! This program takes as input
! a hexadecimal number
! and gives the equivalent decimal
! number as output
! the number is  assumed to be entered MSB first
	integer :: n,m, dec, num
	character :: ch
	
	dec = 0

	do n = 1, 4
	! MSB first
	write (*,*) "Enter position ",n
	read *,ch 
	! checks to see if a number
	num = (IACHAR(ch) - IACHAR('0'))

	if ((num>=0).and.(num<=9)) then
		! entered char is a number
			dec = 16*dec + num
		! checks to see if a char
	else 
			num = (IACHAR(ch) - IACHAR('a'))
			if ( num > 6 ) then
				! entered char is not one of a,b,c,d,e,f
					write *, "Invalid char"
					exit
			else 
					dec = 16*dec + num + 10
			end if

	end if

	end do

	print *, "The decimal equivalent is ", dec

	end program hextodec
