C     Programmer: Becca Gaspard
C     Course: CS430
C     Date Due:9-13-07
C     Language: FORTRAN
C     Compiler used: force2.08
C     Source Filename: program2b.f
C     Professor: Adams
C
C     Purpose: This program takes a decimal value less than or equal to
C     zero and converts to its binary equivalent
C     Required input: user must enter a decimal in the specified range
C     Expected output: the binary equivalent of the user's input,
C     length will be truncated to less than or equal to 6 digits
C     General comments: The program assumes the user will input
C     an integer in the specified range (no error checking)

C     This program will only calculate to 6 decimal places,
C     the binary solution will be stored in this integer array
      DIMENSION NARRAY(6)
      
C     AMAX=2*.5, .5 is the float value of the first decimal
C     place in binary
      AMAX=1
      
C     represents the position of the last significant digit in the
C     binary decimal value so trailing zeros will not be printed,
C     set to 6 by default
      NSTOP=6
      
C     Requests input from the user and echos the input,
C     input is stored in value A(real)
      WRITE(6,10) 'Enter a decimal number less than or equal to zero!'
 10   FORMAT(A50)
      READ(5,11) A
 11   FORMAT(F6.5)
      WRITE(6,12) A
 12   FORMAT('The base 10 value of the input is: ', F6.5)
      
C     This loop assigns a zero to every spot in the array, then divides
C     AMAX by 2.  AMAX now represents the value of the J'th decimal
C     place in the binary array
      DO 60 J=1,6
        AMAX=AMAX/2
        NARRAY(J)=0
C     if A is greater than AMAX, a 1 will be put in the J'th position
C     and the value of the J'th position stored in AMAX will
C     be subtracted from A
        IF(A .LT. AMAX) GO TO 60
          NARRAY(J)=1
          A=A-AMAX
          NSTOP=J
 60   CONTINUE
 
C     Many decimal numbers will have more than 6 digits in binary
C     If there is a remainer left in A after 6 digits, NSTOP is set to 6
C     so that any trailing zeros will still be displayed
      IF(A .EQ. 0) GO TO 61
        NSTOP=6

C     The array is printed on one line from position 1 to NSTOP
 61   WRITE(6,13) (NARRAY(I),I=1,NSTOP)
 13   FORMAT('The base 2 value of the input is: .', 6(6(I1)))

C     This text will appear to show the program has ended
      WRITE(6,14) 'The program has ended normally!'
 14   FORMAT(A35)
 
      STOP
      END
