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

C     Purpose: Convert a decimal number into a binary number
C     Input:  decimal number under 32767
C     Output: a binary number with up to 15 digits
C     General Comments: none
C     Language: I did not use anything new from the last program.

      DIMENSION INPUTTWO(16)
      
C     STOPS AT 2^15
      WRITE(6, 11)
11    FORMAT(1X, "Input an integer less than 32767 ")
    
      READ(5,1) INPUTTEN
1     FORMAT(I5)
    
      Write(6, 12) INPUTTEN
12    FORMAT(1X, "The base 10 of the input is: ", I5)

      CALL BINARY(INPUTTEN, INPUTTWO)
      WRITE(6,14)
14    FORMAT(1X, "The base 2 of the input is: ")
      WRITE (6,13)(INPUTTWO(I), I = 15,1, -1)
13    FORMAT(1X, 16(1(I1)))
      STOP
      END
      
C     Subroutine that does the converting to binary
      SUBROUTINE BINARY(INPUT, IOUTPUT)
C      1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32766
      DIMENSION IOUTPUT(16)
      
      DO 21 I= 15, 0, -1

      IF ((2**I).LE.INPUT)GO TO 32

      IOUTPUT(I+1) = 0
      GO TO 21
      
32    IOUTPUT(I+1) = 1
      INPUT = INPUT-(2**I)

21    CONTINUE
      RETURN
      END
