Re: Porting Binary Files

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: Porting Binary Files
    ... >>>I would like to be able to read a ported binary file (populated only by ... >>>Windows, to a Windows XP PC with a simple FTP. ... >> 1) The format of floating point numbers on the originating machine. ... which you can correct by swapping the 4 bytes in each float: ...
    (microsoft.public.vc.language)
  • Re: x86 exception handling and stack demand
    ... "there isn't any floating point state, ... The current design makes me pay that price regardless. ... Windows, because its just, well, slow. ... optimized accordingly (better to increase the per-thread cost than the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multithreading on Multicore Processors
    ... floating point calculations. ... insomuch as floating point calculation ... The 16 codes of the Polyhedron Fortran benchmark run on both Windows ... management and process priority management has more to do with it. ...
    (comp.lang.fortran)
  • Re: Strange (long double) results from simple program
    ... no error messages anywhere (not during compile, ... Some of the ports of gcc to Windows, such as MinGW, do not provide a ... gcc is passing 80-bit x86 extended precision floating ...
    (comp.lang.c.moderated)
  • Re: Missing 0.0000001 - driving me crazy - help!
    ... >Thanks Philip and Ian, a real help. ... >Working on what Philip said about Windows just rounding, ... You shouldn't use floating point numbers for money; ... with exact integer calculations. ...
    (comp.lang.php)