C      Programmer: Glenn Henderson
C      Course: CS 430
C      Date Due: September 12, 2007
C      Language: FORTRAN
C      Compiler used: FORCE2.08
C      Source Filename: PA2b.f
C      Executable Filename (if any) or None: None
C      Professor: Elizabeth Adams

C     Purpose: The purpose of this program is to convert a base 10
C              decimal into a base 2 decimal
C
C     Input:   Any integer from 1 to 32767
C     Output:  The base 2 representation of the inputed integer
C     Language information
C        DIMENSION indicates that the variable name(s) which follow are arrays
C        The array is an integer array and its size is 6 elements
C        Print prints out a message, the * indicates default device
C        READ is the input statement, using a format of decimal of size 4 with
C             the decimal point at the beginning.
C        We echo the number and then perform the following,
C             take the number and multipy it by 2.  The whole number part of that
C             result is the 1's place.  Then multiply by 2 again, and the whole
C             number part is now the 10's place.  Continue until you fill the
C             array of size six
C        The NCOUNT variable is for printing the number of digits in the array
C             that are important, the IF statement for NCOUNT is so that
C             the print doesn't go out of bounds
C        Once the base 2 decimal string has been calculated it is then printed using
C             and implied do loop passing all the elements of the array to
C             the format statement
C         The format statement is accepting at most 6 integers, the maximum
C             numbers in the base 2 string




      DIMENSION I(6)
      REAL A
      INTEGER NCOUNT

      NCOUNT = 0

      PRINT *, 'Input a decimal number'

      READ(*, 10) A
   10 FORMAT (F4.3)

      WRITE(*, 20) A
   20 FORMAT ('\nThe base 10 value of the input is: ', F4.3)
       
      DO 30 J = 6,1,-1
         A = A * 2

         I(J) = INT(A)

         IF(A .GE. 1) A = A-1
         IF(A .NE. 0) NCOUNT = NCOUNT + 1

   30 CONTINUE

      IF(NCOUNT .EQ. 6) NCOUNT = 5
       
      WRITE (*, 21) (I(K), K=6,(6-NCOUNT),-1)
   21 FORMAT ('The base 2 value of the input is: .', 6I1)

      PRINT *, '\nended successfully'
      
      STOP
      END
