Real

Hello!Does anybody know how can I read in Java a 4-byte number which was written using Fortran.For example in Fortran 1.0 is equal to 00 00 80 3F Thank you in advance.
[203 byte] By [Micky01] at [2007-9-26 1:39:06]
# 1

OK :) I'll try the other way:

I have a file where a different types of data are situated. This file was written in the way which a lot of other languages use : Pascal,Fortran,..(Java use other one!)

For example what I do to read the LongInteger(4-byte) numbers :

name LongInteger is from Pascal

Integer in Pascal consist from two bytes

variable "nomer" is the number of byte from which this current number is beginning if file(I know this info)

// reading LongInt,

private int readLongInt(int nomer){

int LongInteger=0;

try{

int nomerByta = nomer;

theInputStream.seek(nomerByta);

int[] kByte = new int[4];

for (int i=0; i<4; i++){

kByte = theInputStream.read();

}

LongInteger = kByte[0] + kByte[1]*256 + kByte[2]*256*256 + kByte[3]*256*256*256;

}

catch(Exception e){

System.out.println("Exception " + e);

}

return LongInteger;

}

By the way maybe you know the better way how to read LongInt from File ( maybe using >> or >>> )

So the problem how to read Integer data I solved.

But how to read Real?

Thank you for help.

M_Timur at 2007-6-29 2:27:50 > top of Java-index,Archived Forums,Java Programming...
# 2
Micky + M_Timur = love = one
M_Timur at 2007-6-29 2:27:50 > top of Java-index,Archived Forums,Java Programming...
# 3
You can use Float.intBitsToFloat to convert an int that contains the bits of a float into a float. Just use the int your above code generated.
schapel at 2007-6-29 2:27:50 > top of Java-index,Archived Forums,Java Programming...
# 4
So I need only to add one line :?float IntToFloat = Float.intBitsToFloat(LongInteger);and return it ?But if this, I don't receiving what I want. ):
Micky01 at 2007-6-29 2:27:50 > top of Java-index,Archived Forums,Java Programming...
# 5

> But if this, I don't receiving what I want. ):

the jvm uses the IEEE-754 1985 floating-point standard for representing floating points. the values that you have were probably written in another format, hence you are not getting the intended float.

you could try to find a suitable translator on the net or you could write it yourself, if you know the format that was used to write the floats.

parthasarkar at 2007-6-29 2:27:50 > top of Java-index,Archived Forums,Java Programming...