Re: Porting Binary Files
- From: "Severian [MVP]" <severian@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Apr 2005 19:52:10 GMT
On Tue, 12 Apr 2005 12:35:01 -0700, "Maynard"
<Maynard@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>I would like to be able to read a ported binary file (populated only by
>single precision floating point values) from a 32-bit OS that doesn't run
>Windows, to a Windows XP PC with a simple FTP. When I read the data from the
>file on my PC (using fstream object), I can see that the data appears in the
>right locations (I am reading 4 floats...the first and last 4-bytes are the
>same, and the middle 2 4-bytes are the same), but the values are incorrect.
>Does anybody know what might be going on here? Is this a lost cause?
This depends on:
1) The format of floating point numbers on the originating machine.
2) The byte-order of the originating machine.
If the originator uses IEEE floating point, it may just be the second
issue, which you can correct by swapping the 4 bytes in each float:
#include <assert.h>
float GetFloat(BYTE *pf) /* pf is pointer to input buffer */
{
assert(sizeof(long) >= sizeof(float);
return (float)((long)pf[3]|(pf[2]<<8)|(pf[1]<<16)|(pf[0]<<24));
}
If the format is completely different, though, you'll need to find out
more about it and synthesize an IEEE floating point number.
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real
.
- Follow-Ups:
- Re: Porting Binary Files
- From: Maynard
- Re: Porting Binary Files
- From: Simon Trew
- Re: Porting Binary Files
- References:
- Porting Binary Files
- From: Maynard
- Porting Binary Files
- Prev by Date: Porting Binary Files
- Next by Date: Re: Java outperforms C++?
- Previous by thread: Porting Binary Files
- Next by thread: Re: Porting Binary Files
- Index(es):
Relevant Pages
|