C      Programmer: Barclay Roman
C      Course: CS430
C      Date Due: September 13TH, 2007
C      Language: FOTRAN
C      Compiler used: FORCE 2.0
C      Source Filename: PA2-B.f
C      Executable Filename: PA2-B.EXE
C      Professor: Dr. Elizabeth S. Adams
C
C      PURPOSE:  This program will read in a decimal number and print
C                out its base 2 representation.
C
C      INPUT:    The input is a 6 digit float taken from the user.
C
C      OUTPUT:   The output includes the initial program prompt, the
C                base 10 value output, and the base 2 conversion of the
C                number.
C
C      MODIFICATIONS:
C                Like the first part of PA2, converting from base 10 to
C                base 2 was really the only difficult part in this
C                program. I tried several different ways to do this
C                before coming to my conclusion.
C
C      PROGRAM/LANGUAGE COMMENTS:
C                The converting from base 10 to base 2 for this program
C                turned out to be a LOT harder than I thought it would.
C                I, again, felt the language was kind of limited in what
C                it would allow me to do.

       DIMENSION IARRAY(6)

C      DECLARATIONS
C       REAL X

C      INTRODUCTION
       WRITE(6, 70)
   70  FORMAT(1X, /, 'PROGRAMMING ASSIGNMENT #2 Part B - FORTRAN')
       WRITE(6, 72)
   72  FORMAT(1X, /, 'Please enter a 6 digit fraction.')
   
C      Read in the integer
       READ(5, 73) FX
   73  FORMAT(F6.6)

C      Check to see if the number entered is in range
C       IF(X.GE.1) GOTO 71
C       IF(X.LE.0) GOTO 71

       FB = FX
       
C      CONVERSION = X / 2
C      Do Loop to fill the array
       DO 74 I = 1, 6
C       IF(FB.EQ.O) GO TO 74
       
C      Initialize IARRAY
       IARRAY(I) = 0

       IC =  0
       
       IC = IBIN(FB)

       IF(IC.EQ.1) GO TO 75
       FB = FB * 2
       GOTO 80
   75  FB = (FB * 2) - 1

C   30  IF(FB.EQ.O) GO TO 74

C      Fill IARRAY
   80    IARRAY(I) = IC

  74   CONTINUE

C      OUTPUT
       WRITE(6, 90)
   90  FORMAT(/)
       WRITE(6, 91) 'The base 10 value of the input is: ', FX
   91  FORMAT(A, F7.6)
       WRITE(6, 92) (IARRAY(I), I = 1, 6)
   92  FORMAT('The base 2 value of the input is: .', 6(I1))
   
       STOP
       END
       
C      IBIN FUNCTION
C      Used for converting from decimal to binary (Similar to MOD)
       FUNCTION IBIN(FD)
C      Divide value by 2
       IBIN = INT(FD * 2)
C      Get the value to return

       RETURN
       END
