Re: Binary file byte ordering



On 22 Jan, 17:49, groufo...@xxxxxxx wrote:
Hello:

I have a question that I hope someone experienced with Delphi can
answer...

I am using a program to read a binary file that was written in Delphi.
The data is Delphi's extended
precision type, which is 10 bytes. I need to convert those over to a
double precision number (8 bytes)

Here's the question: exactly how does the Delphi compiler interpret
those 10 bytes? I'll take a step
back....I know that the actual readfile is done by a win32 call
through windows app. So I guess
I have 2 questions:

1 - How are the bytes ordered when they are read in? This is critical
because I am reading
in a byte at a time (as U8)

2 - What is the ordering of the bytes....The endian-ness?

I have an algorithm to convert the byes that constitute the extended
precision to doubles,
but I guess it won't be very useful if I cannot get the byes ordered
correctly!


Ignoring endian issues (ie assuming that you have reversed the 10
bytes on an Intel PC) you could bit-twiddle in your own language like
this (Bit0 == LSB) ...

Note value of Bit10(ext)
Discard Bit0 - Bit 10(ext)
Copy Bit11 - Bit62(ext) to Bit0 - Bit51(double)
Discard Bit63 - Bit67 (ext)
Copy Bit68 - Bit79(ext) to Bit52 - Bit63(double)
If Bit10(ext) = 1 then set Bit0(double) to 1

Alternatively a bit of assembler on the FP processor could do it.
Perhals something like ...

Set PC (precision Control) to 11 (64 bits)
Read value into FP
Set PC to 10 (53 bits)
Write value from FP

... but I'm ignorant on assembler <g>

Even better, get an old (v2 onwards) copy of Delphi and write a simple
TFileStream read - convert extended to double - write routine.

Alan Lloyd
.



Relevant Pages

  • Re: Moving from Delphi to C++
    ... is not relevant for Delphi users. ... > Okay, okay, here are two small exercices for you: ... > and no knowledge if this precision is achieved via FPU or SSE2, ... You are not what Borland expect of Delphi "users". ...
    (borland.public.delphi.non-technical)
  • Re: Binary file byte ordering
    ... precision type, which is 10 bytes. ... Conversion is automatic in Delphi; you have not said that you are using ... instruction; that would be a nice function to have in Delphi code. ...
    (alt.comp.lang.borland-delphi)
  • Binary file byte ordering
    ... I am using a program to read a binary file that was written in Delphi. ... precision type, which is 10 bytes. ... through windows app. ...
    (alt.comp.lang.borland-delphi)
  • Re: Need to get natural logarithm of a large integer ln(x)
    ... If I use the Windows calculator I get 8.5993369457292772667692975044269 ... How do I get more precision from Delphi ??? ... Furthermore, your input value has only 8 significant figures, so the ...
    (borland.public.delphi.non-technical)
  • Re: I dont think I will regret RosAsm
    ... It was the assembler - language that taught me this, ... It's really great that assembly and RosAsm have made this concept clear ... data structures and algorithms before attempting this in Delphi, ... You give assembly language programmers a bad name when you mis-use ...
    (alt.lang.asm)