Reading Delphi binary floats

M

MB

Hi,
I have a binary file generated by a Delphi program. I can read all
strings (prefix length strings) but I can't get the float right.

Example: Somewhere in the Hex below store: 40.0 Single (Delphi = 4
bytes)

Hex From file: 00 00 00 00 20 42 00 00 00

- I assume to read 00 00 20 42 but can read from any pos ...

I have tried any type of read and conversion but can't get this one
right (or any floats) from the file.

Any an all help is much appreciated
 
E

EJP

MB said:
Hex From file: 00 00 00 00 20 42 00 00 00

- I assume to read 00 00 20 42 but can read from any pos ...

I don't know what that last sentence means, but 00 00 20 42 looks like a
word-swap. Try swapping it around to 20 42 00 00, then if that doesn't
work try swapping the bytes too. There are a lot of permutations. If you
really want to get this right, find the specification of the Delphi
single-precision FP and work out how to map it to IEEE 754 which is what
Java uses.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

MB said:
I have a binary file generated by a Delphi program. I can read all
strings (prefix length strings) but I can't get the float right.

Example: Somewhere in the Hex below store: 40.0 Single (Delphi = 4
bytes)

Hex From file: 00 00 00 00 20 42 00 00 00

- I assume to read 00 00 20 42 but can read from any pos ...

I have tried any type of read and conversion but can't get this one
right (or any floats) from the file.

import java.io.*;

public class FP {
public static void main(String[] args) throws IOException {
byte[] b = { 0x42, 0x20, 0x00, 0x00 };
DataInputStream dis = new DataInputStream(new
ByteArrayInputStream(b));
float x = dis.readFloat();
System.out.println(x);
}
}

outputs 40.0 !

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top