CC Programmer: James Read

CC Course: CS 430

CC Date Due: 9/12/2007

CC Language: FORTRAN

CC Compiler used: Force 2.0

CC Source Filename: ProgLang2PART2.f

CC Executable Filename (if any) or None: ProgLang2PART2.exe

CC Professor: Elizabeth Adams, JMU Computer Science Dept.;



CC Description of the program's PURPOSE:

CC Reads in a decimal number and prints out its base 2 representation.



CC Description of program's required INPUT:

CC Any decimal number between 0 and 1
CC Due to the need for formatting only the first 6 decimal places are used.




CC Description of program's expected OUTPUT:

CC The decimal number read in is echoed out with a label.
CC The base 2 representation of the number is printed out with a label.



CC Descriptions of any MODIFICATIONS made in debugging the program:

CC Simple math and formatting error corrections.



CC Initial prompt
CC Could not figure out how to get keypress echo on same line as prompt

      WRITE (6,10)
  10  FORMAT (1X, ' Please enter a decimal number between 0 and 1 ')
      READ (5, 20) A
  20  FORMAT (F7.6)


CC Echo of input with label
      WRITE (6, 40) A
  40  FORMAT (1X, ' The base 10 value of the input is:  ', F7.6)


CC Convert the base 10 decimal number to base 2.
CC Prints the value of the conversion function ( DTOBINARY(A) ) directly to screen with label.
      WRITE (6,60) DTOBINARY(A)
  60  FORMAT (1X, ' The base 2 value of the input is: ', F7.6)

      STOP
      END
      

CC DTOBINARY function
CC Converts base 10 decimal numbers from 0 to 1 into base 2 decimals with a maximum of 6 significant digits
CC    Same basic structure as TOBINARY subroutine of part A.
CC      Biggest difference is no use of arrays to hold the binary value.  Limited significant digits allowed
CC      the value to be stored as a real. This also made it much simpler to pass and display.
CC
CC      The math is different but the function uses the same basic loop format.
CC      Uses IF statement to create a do while loop.
      FUNCTION DTOBINARY(B)
      G = B
      C = 0.0
      E = 1.0
 120  IF (G*2 .LT. 1.0) GO TO 130
      C = (C + 10.0**(-E))
 130  G = MOD(G*2.0,1.0)
      E = E+1.0
      IF (E .EQ. 7.0) GO TO 140
      IF (G .NE. 0.0) GO TO 120
 140  DTOBINARY = C
      RETURN
      END
      
