C     Programmer: Josh Ginsburg
C     Course:    CS 430
C     Date Due:   Wednesday September 12, 2007 11:59pm
C     Language:  FORTRAN
C     Compiler used:  Force 2.0.8
C     Source Filename: PA2A.f
C     Executable Filename (if any) or None: PA2A.exe
C     Professor: Dr. Adams

C     Description of the program's PURPOSE:
C         Program which will read in a decimal number and print out
C          its base 2 representation. The base 10 decimal read in should
C          be echoed out with a label and the base 2 result should be
C          printed out with a label.

C      Description of program's required INPUT:
C         Read in a base 10 integer


C      Description of program's expected OUTPUT:
C          The inputted base 10 integer should be outputted along
C          with the base 2 conversion of it.

C      Descriptions of any MODIFICATIONS made in debugging the program:
C            The majority spent of the debugging was getting the base
C           conversion algorithm to work properly, and also output in
C           the correct format. The array took time aswell.

C      General COMMENTS about the PROGRAM
C           The major problem was realizing I had to use an array to
C           display the 15 binary places. INTEGER or REAL was to small
C           of a format. Integrating the array was a real pain.
C          Numbers are assumed to be positive
C          No error checking is performed

C      General COMMENTS explaining the syntax or features of the LANGUAGE
C         The biggest feature of this program, is printing the array out
C         in reverse order.

C       !Declare the variables to be used
       INTEGER VAR
       INTEGER SUM(15)
       INTEGER I
       
C      Ask user to input an Integer between 1 and 32767
       WRITE (6, 2)
       
C      Format for output statement
2      FORMAT (1X, "Please enter an integer between 1-32767")

C      Read in the variable and store it in the Integer VAR
       READ(5,4) VAR
       
C      The format for VAR
4      FORMAT(I5)

C      Echo the Integer the user inputted
       WRITE (6, 6) VAR
       
C      Format for output statement and variable (I5) Integer of 5 length
6      FORMAT (1X, "The base 10 value of the input is: ", I5)

C      DO loop that runs 15 times (MAX Length of Array)
       DO 8 I = 1, 15
       
C      Either a 1 or 0, the MOD of VAR when divided by 2
       SUM(I) = MOD(VAR,2)

C      Divide the VAR by 2 and repeat until VAR = 0
       VAR = VAR / 2

C      Continue the DO loop
8      CONTINUE

C      Output the converted integer which is now stored in an array.
C      We must output the array in reverse order for it to be properly
C      in binary
       WRITE (6,10) (SUM(I), I = 15,1, -1)
       
C      Format of the message and array
10     FORMAT (1X, "The base 2 value of the input is: ", 15(I1))

C      End the program
       END

       
