C      Programmer: Mike Garrett

C      Course: CS 430

C      Date Due: September 13, 2007

C      Language: FORTRAN

C      Compiler used: FORCE2.08

C      Source Filename: PA2B.F

C      Executable Filename (if any) or None: PA2B.EXE

C      Professor: Dr. Elizabeth Adams



C      Purpose: The purpose of this program is to take in a floating
C               point decimal between 0 and 1 in base 10 from the
C               user, and convert it to base 2.
C
C      Input: The input for this program will be a floating point (REAL)
C             number between 0 and 1.
C
C      Output: The output will first be the input echoed
C              back to the user, and then the number converted to base
C              2 is outputted.
C
C      Language information:
C              GO TO Statement requires a label.
C              .GE. means Greater than or equal to.
C              .LT. stands for less than
C
C
C     ##################################################################
C       MAIN PROGRAM
C     ##################################################################

C     Declare my array to hold binary representation of the input
C     Size is 6 since we only need to record 6 decimal places.
      DIMENSION IBIN(6)
      
C     Prompt user for input and read it in
      WRITE(6,19)
      READ(5,21) DEC

C     Echo the input back to the user
      WRITE(6,20) DEC
      
C     In this loop we are going to record the first 6 decimal places
C     for the binary representation of the input. The way we do this
C     is by first multiplying our current base 10 number by 2. We then
C     check if the new number is greater than or equal to 1, if it is
C     we record a 1 for that decimal place and subtract 1 from the
C     decimal value. If it is less than 1 then we record a 0.
      DO 10 I = 1, 6
      DEC = DEC * 2.0
      IF (DEC .GE. 1.0) GO TO 30
      IF (DEC .LT. 1.0) IBIN(I) = 0
C     Following GO TO is in place so we skip the
C     calculations in Label 30
      GO TO 10
  30  IBIN(I) = 1
      DEC = DEC - 1.0
  10  CONTINUE

C     After we calculated the binary number we output it to the user
C     This uses an implied Do loop to iterate through the array
      WRITE(6,22) (IBIN(I), I = 1, 6)
      
C     Format labels:
C            19: This is the output label for the input prompt
C            20: Output label for the echoed input
C            21: Format for the inputted decimal
C                NOTE: it is F7.6 instead of F6.6 to make up for the
C                      decimal place in the input
C            22: Output label for the binary number obtained

  19  FORMAT('Enter an decimal between 0 and 1:')
  20  FORMAT('The base 10 value of the input is:',1X,F7.6)
  21  FORMAT(F6.6)
  22  FORMAT('The base 2 value of the input is:',1X,'.',6(I1))
      STOP
      END
C     END MAIN PROGRAM
