Solved

Binary to Decimal in FORTRAN

Posted on 2004-09-21
7
1,922 Views
Last Modified: 2013-11-15
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.
0
Comment
Question by:jjohn110
  • 4
  • 3
7 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 12119165


When you say "convert binary to decimal" are you really just wanting to display the value of an integer/float?  Or are you wanting to do a "dump" of a buffer?  This is a bit ugly, but it should get you a good start.

Kent


       PROGRAM DUMPX
       CHARACTER XSTRING(80)
       INTEGER IARRAY(20)

       DUMPIT (XSTRING, 80)
       DUMPIT (IARRAY, 80)

       END


       SUBROUTINE DUMPIT (IARRAY, LENGTH)
       INTEGER IARRAY(20);
       INTEGER LENGTH

       DO 10 I=1, LENGTH, 4
       W1 = IARRAY(I) / (256 * 3)
       W2 = (IARRAY(I) - (W1 * (256 * 3))) / (256 * 2)
       W3 = (IARRAY(i) - (W1 * (256 * 3)) - (W2 * (256 * 2))) / 256
       W4 = (IARRAY(i) - (W1 * (256 * 3)) - (W2 * (256 * 2)) - (W3 * 256))
       WRITE (6, 'I2 I2 I2 I2', W1, W2, W3, W4)
 10   CONTINUE
       END


0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12120060
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
0
 
LVL 45

Expert Comment

by:Kdo
ID: 12121909

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


0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 12122048
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
0
 
LVL 45

Expert Comment

by:Kdo
ID: 12122239

[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
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12130936
<shudder> ignorance IS a bliss ;o)
0
 
LVL 45

Expert Comment

by:Kdo
ID: 12132082

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

0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Choppy program performance on Windows Server 2012 20 84
wordcount challenge 11 106
Problem to event 3 76
Acrinis True image 2 57
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now