*     Programmer:  Ji Kwon Lim
*     Course:  CS430
*     Date Due:  Sep 13, 2007
*     Language:  FORTRAN
*     Compiler Used:  Force 2.08
*     Source Filename:  PA2B.f
*     Executable Filename:  PA2B.exe
*     Professor:  Adams
*
*     Description of the program's PURPOSE:
*       This program converts a base 10 fraction to binary
*
*     Description of program's required INPUT:
*       An integer input between 0 amd 1
*
*     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:
*
*     General COMMENTS about the PROGRAM
*       It is not error proofed against invalid inputs.
*
*     General COMMENTS explaining the syntax or features of the LANGUAGE
*       There isn't anything in part B that the COMMENTS in part A
*       doesn't mention.  Formatting for decimal numbers seems
*       particularly restricting as a set number of columns and decimal
*       places need to be decided ahead of time.

*     Will hold the digits of the binary representation
        DIMENSION I(6)
        
*     User introduction to the program
        WRITE(6,10) 'This program takes an decimal input and returns'
        WRITE(6,10) 'its binary representation.                   '
10      FORMAT(A65)

*     Takes decimal input from the user
        WRITE(6,11) ''
        WRITE(6,11) ''
        WRITE(6,11) 'Enter decimal input (0-1): '
        READ(5, 20) DECIMAL
        
11      FORMAT(A28)
20      FORMAT(F12.10)

*     Algorithm for finding binary representation of decimals.
        D = DECIMAL
        LAST = 1
        DO 50 J = 1, 6, 1
          D = D * 2
          IF (D .LT. 1.0) GO TO 51
            I(J) = 1
            D = D - 1.0
            LAST = J
            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) DECIMAL
        WRITE(6,13) (I(J), J = 1, LAST)
        
12      FORMAT('The base 10 value of the input is: ', F12.10)
13      FORMAT('The base  2 value of the input is: 0.', 6(I1))

        STOP
      END
