Link to home
Start Free TrialLog in
Avatar of jjohn110
jjohn110

asked on

Binary to Decimal in FORTRAN

I was wondering if anybody knew a program for converting binary to decimal using Fortran. I'm trying to help out a student of mine and I don't know much about Fortran.
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Kent,

Beware :-) ... this might turn out to be an assignment. I would not teach a student in a language which I do not know ;o) ...

Since I dont know F of FORTRAN, your call to draw the line.

cheers
sunnycoder

Hi Sunny,

This functionality was ugly to install into FORTRAN code.  Largely because the resulting file became dependent on the underlying architecture (and ultimately compiler extensions).  Everywhere that I ever worked that made extensive use of FORTRAN wound up having to do this sort of thing, so I didn't take this as homework.

The easiest, best, and fastest way is to write an assembly coded subroutine to convert the buffer so that the FORTRAN code simply did I/O, thereby adding to the machine dependence.  But most application coders don't know assembly language, so that's not an option.

And then there's the shifting and masking issue.  I resolved it with simply math, but that fits nicely into an assembly subroutine.  Very few newbies would work out this math, so if it is a homework assignment someone will have quite a bit of explaining to do.  :)

This code's dependent on a 32-bit system and may suffer from "odd results" depending on the sign bit.  Also, I haven't had a FORTRAN compiler for 20 years so there's certainly no guarantee that this will compile.  :)


Thanks for lookin' out for me, Sunny.
Kent


Glad that I never found FORTRAN .... but then, I was born in easier times ;o)

Are you feeling jealous of me :-D ... lol

I trust your call Kent ... It was just a gentle reminder, just to be on the safe side ...

cheers mate

[PPtttttttt]

Speaking of machine dependence, one series of systems that I used many years ago (and still consult on) reserved the first two words of a job for system communication.  Jobs made system requests by placing a non-null value into the second word (word 1, counting from zero :) ).

A non-standard system request from FORTRAN looked like this:

       INTEGER REQUEST
       INTEGER SYS(1)

      *  Build the request string into the integer variable REQUEST

       SYS(2 - LOC(SYS)) = REQUEST
   10 IF (SYS(2 - LOC(SYS)) .NE. 0)
       GO TO 10

Try getting that to work in Windows.  ;-)


Kent
<shudder> ignorance IS a bliss ;o)

If so, there are an awful lot of "Happy Campers" around the boards....  ;-)