C     Programmer: John Labowskie
C     Course:     CS 340
C     Date Due:   Sept 5, 2007
C     Language:   Fortran
C     Compiler:   Force 2.0
C     Source File: Fortran_program2b.f
C     Professor:   Adams

C     Purpose: to convert a decimal in base 10 to base 2 up to 6 places
C     Input: A decimal number with no values up above the tenths place
C     Output: A decimal binary number rounded to the 6th place
C     General Comments: None
C     Language: I used nothing new from the first program.

      DIMENSION IOUTPUT(6)

      WRITE(6, 11)
11    FORMAT(1X, "Input a base 10 decimal: ")

      READ(5,1) AINPUT
1     FORMAT(F5.4)

      WRITE(6, 12) AINPUT
12    FORMAT(1X, "The base 10 of the input is: ", F5.4)

      CALL CONVERT(AINPUT, IOUTPUT)

      WRITE(6,14) (IOUTPUT(I), I = 1,6)
14    FORMAT(1X, "The base 2 of the input is: .", 6(1(I1)))

      STOP
      END
      
C     subroutine to convert the base 10 to base 2
      SUBROUTINE CONVERT(DECIMAL, IBINARY)
      DIMENSION IBINARY(6)

      DO 21 I= 1, 6

      IF (((2.0**(-I)).LE.DECIMAL) .AND. (DECIMAL.NE.0))GO TO 32

      IBINARY(I) = 0
      GO TO 21

32    DECIMAL = DECIMAL-(2.0**(-I))
      IBINARY(I) = 1

21    CONTINUE
      RETURN
      END
