Wrong Byte order when writing with a binary writer  
Author Message
ToddBailey





PostPosted: Thu Sep 11 00:29:29 CDT 2003 Top

Net Framework >> Wrong Byte order when writing with a binary writer Hi!

I have the following problem:

I want to write an integer value (e.g. 14) with a binarywriter.

The written file contains the following entry:
0E 00 00 00

I want the entry to be the following:
00 00 00 0E

Does anybody know how to get the desired result (Language vb)?

Thanks in advance,
Marko

DotNet314  
 
 
William





PostPosted: Thu Sep 11 00:29:29 CDT 2003 Top

Net Framework >> Wrong Byte order when writing with a binary writer Check out IPAddress.NetworkToHostOrder and hosttonetworkorder to change
endian-ness.

--
William Stacey, DNS MVP

"Marko Maehner" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Hi!
>
> I have the following problem:
>
> I want to write an integer value (e.g. 14) with a binarywriter.
>
> The written file contains the following entry:
> 0E 00 00 00
>
> I want the entry to be the following:
> 00 00 00 0E
>
> Does anybody know how to get the desired result (Language vb)?
>
> Thanks in advance,
> Marko


 
 
Magnus





PostPosted: Thu Sep 11 01:20:51 CDT 2003 Top

Net Framework >> Wrong Byte order when writing with a binary writer The byte order is not wrong since Windows is big-endian. If you need to
control the byte order you can stream it byte per byte yourself. That way
you can store integers in litte-endian instead. But why? If you use a binary
reader to read integers you will receive the same value as stored with the
binary writer. I can see the problem if you write data on a big-endian
system and read the data on a little-endian system but that can all be
solved by adding a header containing information about the "endianess".

/M

"Marko Maehner" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Hi!
>
> I have the following problem:
>
> I want to write an integer value (e.g. 14) with a binarywriter.
>
> The written file contains the following entry:
> 0E 00 00 00
>
> I want the entry to be the following:
> 00 00 00 0E
>
> Does anybody know how to get the desired result (Language vb)?
>
> Thanks in advance,
> Marko


 
 
Daniel





PostPosted: Thu Sep 11 02:25:33 CDT 2003 Top

Net Framework >> Wrong Byte order when writing with a binary writer
"Magnus Persson" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> The byte order is not wrong since Windows is big-endian. If you need to
> control the byte order you can stream it byte per byte yourself. That way
> you can store integers in litte-endian instead. But why? If you use a
binary
> reader to read integers you will receive the same value as stored with the
> binary writer. I can see the problem if you write data on a big-endian
> system and read the data on a little-endian system but that can all be
> solved by adding a header containing information about the "endianess".
>
If, of course, you have any say in the format. Pretty possible thats been
determined by parties well outside of the OP.
Also, Intel chips are little endian and Windows and native programs, by
extension, usually use use little endian integers nativly. The .NET CLR is
big endian as I recall, which is frustrating at times for binary
interopability with legacy native code. I assume that the JIT'er handles the
endian conversions for code execution, but that doesn't help with writing
binary data.
On other processors, the endian'ness (is there a proper term for this?) can
change. Assuming you get rotor or mono to work on the mac, you are on a
processor that, I think, can be either. However, I believe Mac OS uses
big-endian and native code would for that platform is more likely expect big
endian integers. I'm not sure on all these points, someone correct me if I'm
mistaken please.
Its something we all have to be used to sometimes...

> /M
>
> "Marko Maehner" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > Hi!
> >
> > I have the following problem:
> >
> > I want to write an integer value (e.g. 14) with a binarywriter.
> >
> > The written file contains the following entry:
> > 0E 00 00 00
> >
> > I want the entry to be the following:
> > 00 00 00 0E
> >
> > Does anybody know how to get the desired result (Language vb)?
> >
> > Thanks in advance,
> > Marko
>
>


 
 
marko





PostPosted: Thu Sep 11 03:19:39 CDT 2003 Top

Net Framework >> Wrong Byte order when writing with a binary writer Further information: The written binary file will be sent to another
system (little endian), so it doesn't help to be able to read the data
with an binary reader.
 
 
Magnus





PostPosted: Mon Sep 15 01:58:41 CDT 2003 Top

Net Framework >> Wrong Byte order when writing with a binary writer Oops, I did mixup the big/little endian stuff.
Intel chips are little-endian and when running Windows 9x/Me/NT/2k/XP on
intel chips the OS will also be little-endian.

I did develop programs for BeOS some time ago (was also a beta tester for
both version 4 and version 5 of BeOS) and since that OS run on PowerPC
(which is bi-endian) there were APIs to determin if the system was big or
little-endian (neet). To bad that OS didn't make it (well...it's not dead
yet).

"Daniel O'Connell" <EMail@HideDomain.com> wrote in message
news:NrV7b.417453$uu5.75746@sccrnsc04...
>
> "Magnus Persson" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > The byte order is not wrong since Windows is big-endian. If you need to
> > control the byte order you can stream it byte per byte yourself. That
way
> > you can store integers in litte-endian instead. But why? If you use a
> binary
> > reader to read integers you will receive the same value as stored with
the
> > binary writer. I can see the problem if you write data on a big-endian
> > system and read the data on a little-endian system but that can all be
> > solved by adding a header containing information about the "endianess".
> >
> If, of course, you have any say in the format. Pretty possible thats been
> determined by parties well outside of the OP.
> Also, Intel chips are little endian and Windows and native programs, by
> extension, usually use use little endian integers nativly. The .NET CLR is
> big endian as I recall, which is frustrating at times for binary
> interopability with legacy native code. I assume that the JIT'er handles
the
> endian conversions for code execution, but that doesn't help with writing
> binary data.
> On other processors, the endian'ness (is there a proper term for this?)
can
> change. Assuming you get rotor or mono to work on the mac, you are on a
> processor that, I think, can be either. However, I believe Mac OS uses
> big-endian and native code would for that platform is more likely expect
big
> endian integers. I'm not sure on all these points, someone correct me if
I'm
> mistaken please.
> Its something we all have to be used to sometimes...
>
> > /M
> >
> > "Marko Maehner" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> > > Hi!
> > >
> > > I have the following problem:
> > >
> > > I want to write an integer value (e.g. 14) with a binarywriter.
> > >
> > > The written file contains the following entry:
> > > 0E 00 00 00
> > >
> > > I want the entry to be the following:
> > > 00 00 00 0E
> > >
> > > Does anybody know how to get the desired result (Language vb)?
> > >
> > > Thanks in advance,
> > > Marko
> >
> >
>
>