*     Programmer:  Ji Kwon Lim
*     Course:  CS430
*     Date Due:  Sep 13, 2007
*     Language:  FORTRAN
*     Compiler Used:  Force 2.08
*     Source Filename:  PA2A.f
*     Executable Filename:  PA2A.exe
*     Professor:  Adams
*
*     Description of the program's PURPOSE:
*       This program converts a base 10 integer number to binary
*
*     Description of program's required INPUT:
*       An integer input between 1 and 32767
*
*     Description of program's expected OUTPUT:
*       An echo of the base 10 input and its base 2 representation
*
*     Descriptions of any MODIFICATIONS made in debugging the program:
*       Only modifications necessary were to formatting
*
*     General COMMENTS about the PROGRAM
*       It is not error proofed against invalid inputs.
*       The array was kept to 15 digits as 32767 is (2**15)-1
*
*     General COMMENTS explaining the syntax or features of the LANGUAGE
*       Although the degree of output and input formatting is quite
*       extensive, the constant need to set a format for inputs and
*       outputs can be tedious. The use of GO TO for the IF statements
*       is also confusing at first.  In other languages, the statements
*       directly under the IF statements are the one to perform if the
*       condition is true.  In this language, those statements are the
*       ones that are skipped if true, which forces you to think in
*       reverse.

*     Will hold the digits of the binary representation
        DIMENSION I(15)

*     User introduction to the program
        WRITE(6,10) 'This program takes an integer input and returns'
        WRITE(6,10) 'its binary representation.                   '
10      FORMAT(A65)

*     Takes integer input from the user
        WRITE(6,11) ''
        WRITE(6,11) ''
        WRITE(6,11) 'Enter integer input (1-32767): '
        READ(5, 20) INPUT
        
11      FORMAT(A32)
20      FORMAT(I5)

*     Algorithm for finding binary representation of integers.
        K = INPUT
        DO 50 J = 15, 1, -1
          IF (K .LT. 2**(J-1)) GO TO 51
            I(J) = 1
            K = K - 2**(J-1)
            GO TO 52
51        I(J) = 0
52        DONOTHING = 0
50      CONTINUE

*     Output of the user input and its binary representation.
        WRITE(6,11) ''
        WRITE(6,11) ''
        WRITE(6,12) INPUT
        WRITE(6,13) (I(J), J = 15, 1, -1)
        
12      FORMAT('The base 10 value of the input is: ', I5)
13      FORMAT('The base  2 value of the input is: ', 15(I1))

        STOP
      END
