C      Programmer: Luke Ryan
C      Course: CS430
C      Date Due: 09/12/07
C      Language: FORTRAN
C      Compiler Used: Force 2.0
C      Source Filename: PA2.f
C      Executable Filename: N/A
C      Professor: Elizabeth Adams

C      Description of the program's PURPOSE:
C      To convert a decimal integer and a decimal fraction to binary
C      notation.

C      Description of program's required INPUT:
C      One Integer between the values of 1 and 32767 and
C      One decimal value that contains siz digits or less.

C      Description of the program's required OUTPUT:
C      The inputed Integer labeled followed by it's value in binary notation
C      labeled.
C      The inputed Decimal point labeled followed by it's value in binary
C      notation labeled.

C      Descripton of any MODIFICATIONS made in debugging the program:
C      Another digit had to be added for inputting the decimal point
C      so that the right value was recorded.

C      General COMMENTS about the PROGRAM:
C      The decimal value is assumed to be positive
C      The LOOPCOUNTER variable is used in two seperate loops

C      General COMMENTS explaining the syntax or features of the PROGRAM:
C      MOD is used to find the remainder of the first parameter decided by
C      the second.


       DIMENSION NBINARYNUMBERS(15)
       NUMBERTWO = 2
       LOOPCOUNTER = 0

C      Prompts the user for an Integer
       WRITE (6, 1)
   1   FORMAT (' ', 'Enter an integer value between 1 and 32767')
       READ (5, 2) INT
   2   FORMAT (I5)
C      Checks to see that the Integer is between 1 and 32767
       IF ( ( INT .LT. 1 ) .OR. ( INT .GT. 32767 ) ) GO TO 50

C      Echo the Integer
       WRITE(6, 7)
   7   FORMAT(' ')
       WRITE (6, 8) INT
   8   FORMAT (1X, 'The base 10 value of the input is: ', I5)

C      Find the Binary value of the Integer by adding a one if the Integer
C      is indivisble by 2 followed by the subtraction of 1 and divistion by 2.
C      This is repeated until 0 is reached.
       DO 3 M = 1, 15
          J = MOD(INT, NUMBERTWO)
          IF ( J .EQ. 0 ) GO TO 4
          INT = INT - 1
          NBINARYNUMBERS(M) = 1
          GO TO 5
   4      NBINARYNUMBERS(M) = 0
   5      INT = INT / NUMBERTWO
          LOOPCOUNTER = LOOPCOUNTER + 1
          IF ( INT .EQ. 0 ) GO TO 6
   3   CONTINUE

C      Echo the Binary value of the inputed Integer as the array backwards
   6   WRITE (6, 9) 'The base 2 value of the input is: ',
     C (NBINARYNUMBERS(I), I = LOOPCOUNTER, 1, -1)
   9   FORMAT (A35, 15I1)

C      Prompts the user for the decimal point value
       WRITE(6, 7)
       WRITE (6, 10)
  10   FORMAT (' ', 'Enter a 6 digit or less base 10 decimal value')
       READ (5, 11) DECIMAL
  11   FORMAT (F7.7)
  
C      Echoes the decimal point value entered
       WRITE(6, 7)
       WRITE (6, 12) DECIMAL
  12   FORMAT (1X, 'The base 10 value of the input is: ', F7.6)

C      Reset the Loop counter
       LOOPCOUNTER = 1

C      Convert the decimal value to binary
       DO 15 A = 1.0, 6.0
C         Find the current binary place value
          EXP = -A
          B = 2.0 ** EXP
C         Check if the current binary value is greater than the inputed value
          IF ( DECIMAL .LT. B ) GO TO 13
C         Add a one to the current binary value place if it is greater than
C         the inputed value.
          NBINARYNUMBERS(LOOPCOUNTER) = 1
C         Subtract the current binary value from the inputed value
          DECIMAL = DECIMAL - B
          GO TO 14
  13      NBINARYNUMBERS(LOOPCOUNTER) = 0
C         Check to see if the value is 0 if so exit the loop
  14      IF ( DECIMAL .EQ. 0.0 ) GO TO 16
          LOOPCOUNTER = LOOPCOUNTER + 1
  15   CONTINUE

C      Output the binary value of the inputed decimal point
  16   WRITE (6, 17) 'The base 2 value of the input is: .',
     C (NBINARYNUMBERS(I), I = 1,LOOPCOUNTER )
  17   FORMAT (1X,A35, 6I1)
  50   STOP
       END
