Re: Binary file byte ordering
- From: Dr J R Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 22 Jan 2008 20:22:01 +0000
In alt.comp.lang.borland-delphi message <8db81f2c-385f-478d-90ff-
1e82339e8de3@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, Tue, 22 Jan 2008 09:49:20,
groufosse@xxxxxxx posted:
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)
Conversion is automatic in Delphi; you have not said that you are using
an inferior programming language.
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!
Within a byte, the bits are in the standard order for PC CPUs.
There are only two reasonable possibilities for the order of the bytes,
and only one of them will give sensible results; you presumably expect
the data to be within the Double range, with 11 exponent bits, and
extended has 15 exponent bits. Starting at the wrong end, and other
things being equal, there's only one chance in 2^4 of any one datum
fitting in Double, let alone being of plausible magnitude.
The sign bit is always the MSB of the highest byte.
Someone here may know whether, and if so how, an Extended can be stored
in the FPU by an instruction AND read back as Double by another
instruction; that would be a nice function to have in Delphi code. In
fact, to anyone with a low-level Delphi debugger working, the answer to
that might be obvious on inspecting the code for Double := Extended ; .
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Delphi 3? Turnpike 6.05
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.html> news:borland.* Guidelines
.
- References:
- Binary file byte ordering
- From: groufosse
- Binary file byte ordering
- Prev by Date: Re: pipe > redirection bug in Windows XP x64 Pro !!!!!?????!!!!!! 1> output.txt ?????
- Next by Date: Re: pipe > redirection bug in Windows XP x64 Pro !!!!!?????!!!!!! 1> output.txt ?????
- Previous by thread: Re: Binary file byte ordering
- Next by thread: Re: Binary file byte ordering
- Index(es):
Relevant Pages
|