C      Programmer: Mike Garrett

C      Course: CS 430

C      Date Due: September 13, 2007

C      Language: FORTRAN

C      Compiler used: FORCE2.08

C      Source Filename: PA2A.F

C      Executable Filename (if any) or None: PA2A.EXE

C      Professor: Dr. Elizabeth Adams



C      Purpose: The purpose of this program is to take in an integer
C               in base 10 from the user, and convert it to base 2.
C
C      Input: The input for this program will be an integer from
C             1 to 32767.
C
C      Output: The output will first be the integer inputted echoed
C              back to the user, and then the number converted to base
C              2 is outputted.
C
C      Language information:
C               The MOD function is an intrinsic function. It
C               calculates the modulus for any type you send it.
C               DIMENSION declares an array.
C
C
C     ##################################################################
C       MAIN PROGRAM
C     ##################################################################

C     Declare my array to hold binary representation of the input
C     Size is 15 since the maximum number inputted is 32767 which is
C     2^15
      DIMENSION IBIN(15)
      
C     Prompt for input and read it in
      WRITE(6,19)
      READ(5,21) IN
      
C     Echo the input back to the user
      WRITE(6,20) IN
      
C     In this loop we are converting the decimal integer to a binary
C     number. We do this by taking the modulus of the input and 2
C     This is because it will result in a 1 or a 0. We then reset
C     the decimal number by dividing it by 2. The array is holding
C     the data in reverse order.
      DO 10 I = 1, 15
      IBIN(I) = MOD(IN,2)
      IN = IN / 2
  10  CONTINUE

C     Output the binary number to the user
C     This uses an implied do loop decrementing through the array
      WRITE(6,22) (IBIN(I), I = 15, 1, -1)
      
C     Format labels:
C            19: This is the output label for the input prompt
C            20: Output label for the echoed input
C            21: Format for the inputted integer
C            22: Output label for the binary number obtained
  19  FORMAT('Enter an integer between 1 to 32767')
  20  FORMAT('The base 10 value of the input is:',1X,I5)
  21  FORMAT(I5)
  22  FORMAT('The base 2 value of the input is:',1X,15(I1))
      STOP
      END
C     END MAIN PROGRAM
