Re: Porting Binary Files



On Wed, 13 Apr 2005 08:09:06 -0700, "Maynard"
<Maynard@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>"Severian [MVP]" wrote:
>> 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.
>
>I think I follow now (Big Endian vs. Little Endian)...one stupid question
>though...how do I create a pointer to the leading byte in a float?

I wouldn't read the data directly into floats; the reversed bytes may
produce an NaN. I would recommend reading into a byte buffer, then
converting 4 bytes at a time to a float.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real
.



Relevant Pages

  • Re: Porting Binary Files
    ... >>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: ... > more about it and synthesize an IEEE floating point number. ...
    (microsoft.public.vc.language)
  • 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. ... The format of floating point numbers on the originating machine. ...
    (microsoft.public.vc.language)
  • Re: dockable windows
    ... How can you do that with java? ... AFAIK java only lets you dock and ... float around windows -inside a frame- ... setFloat(String, float) - Method in interface javax.sql.RowSet ...
    (comp.lang.java.gui)
  • Re: SysTray Clock:Can I make the DATE appear too?
    ... Windows XP Home. ... I want to be able to force the DATE to float just slightly above ... and resize it to two rows. ... Joe =o) ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: SysTray Clock:Can I make the DATE appear too?
    ... Windows XP Home. ... I want to be able to force the DATE to float just slightly above ... I've searched and cannot find a app/software to do this for me. ... I found this nice little free program which gives me the time, ...
    (microsoft.public.windowsxp.help_and_support)