C      Programmer: Barclay Roman
C      Course: CS430
C      Date Due: September 13TH, 2007
C      Language: FOTRAN
C      Compiler used: FORCE 2.0
C      Source Filename: PA2-A.f
C      Executable Filename: PA2-A.EXE
C      Professor: Dr. Elizabeth S. Adams
C
C      PURPOSE:  This program will read in an integer and print out its
C                base 2 representation.
C
C      INPUT:    The input is an integer from 1 to 32767 taken from the
C                user.
C
C      OUTPUT:   The output includes the initial program prompt, the
C                base 10 value output, and the base 2 conversion of the
C                number.
C
C      MODIFICATIONS:
C                Converting from base 10 to base 2 was really the only
C                difficult part in this program. I tried several
C                different ways to do this before coming to my
C                conclusion.
C
C      PROGRAM/LANGUAGE COMMENTS:
C                The converting from base 10 to base 2 for this program
C                turned out to be a LOT harder than I thought it would.
C                I felt the language was kind of limited in what it
C                would allow me to do.


C      DECLARATIONS
C      IARRAY = base 2 representation of the number
       DIMENSION IARRAY(15)
C      IA = number from the user, IB & IC = numbers used for conversion
       INTEGER IA,IB,IC

C      INTRODUCTION
       WRITE(6, 70)
   70  FORMAT(1X, /, 'PROGRAMMING ASSIGNMENT #2 Part A - FORTRAN')
C      Prompt for user input
   71  WRITE(6, 72)
   72  FORMAT(1X, /, 'Please enter an integer from 1 to 32767.')

C      Read in the integer to IA
       READ(5, 73) IA
   73  FORMAT(I6)

C      Check to see if the number entered is in range
       IF(IA.GT.32767.OR.IA.LT.1) GOTO 71

C      BASE 10 TO BASE 2 CONVERSION
C      Set IB equal to IA
       IB = IA
C      Do Loop to fill the array
       DO 74 I = 1, 15
C      Initialize IARRAY
       IARRAY(16 - I) = 0
       IF(IB.LT.1) GO TO 74
C      Initialize IC
       IC =  0
C      Call BIN Function
       IC = BIN(IB)
       IB = IB / 2
C      Fill IARRAY
       IARRAY(16 - I) = IC
  74   CONTINUE

C      OUTPUT (Integer in base 10 and converted to base 2)
       WRITE(6, 90)
   90  FORMAT(/)
C      Base 10 value output
       WRITE(6, 91) 'The base 10 value of the input is: ', IA
   91  FORMAT(A, I5)
C      Base 2 value output
       WRITE(6, 92) (IARRAY(J), J = 1, 15)
   92  FORMAT(1x, /, 'The base 2 value of the input is: ', 15(I1))
   
       STOP
       END
       

C      BIN FUNCTION
C      Used for converting from decimal to binary (Similar to MOD)
       FUNCTION BIN(ID)
C      Divide value by 2
       IE = ID / 2
C      Get the value to return
       BIN = ID - (2 * IE)
       RETURN
       END
