PC Review


Reply
Thread Tools Rate Thread

BinaryReader and BinaryWriter and Endianess

 
 
Paul Selormey
Guest
Posts: n/a
 
      30th Jan 2004
..NET is mainly designed for Windows and could be assumed to
work with only little endian binary files.

However, what is the real behavior?

BinaryReader : Is this designed to read system/hardware supported
endian of will always read little endian no matter the system?

BinaryWriter: Is this designed to always write little endian binary or
it depends on the system?

I wish to know in order to extend these classes.

BTW, anyone got extends to support big endian binary files?

Best regards,
Paul.

 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      30th Jan 2004
Thats implementation specific for the runtime ported to whatever underlaying
platform shouldnt it?


"Paul Selormey" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> .NET is mainly designed for Windows and could be assumed to
> work with only little endian binary files.
>
> However, what is the real behavior?
>
> BinaryReader : Is this designed to read system/hardware supported
> endian of will always read little endian no matter the system?
>
> BinaryWriter: Is this designed to always write little endian binary or
> it depends on the system?
>
> I wish to know in order to extend these classes.
>
> BTW, anyone got extends to support big endian binary files?
>
> Best regards,
> Paul.
>



 
Reply With Quote
 
Paul Selormey
Guest
Posts: n/a
 
      30th Jan 2004
So, for the .NET framework implemented by Microsoft for the
Windows, what is the picture like? (could not find any hint in the
documents)

Best regards,
Paul.


<(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Thats implementation specific for the runtime ported to whatever

underlaying
> platform shouldnt it?
>
>
> "Paul Selormey" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > .NET is mainly designed for Windows and could be assumed to
> > work with only little endian binary files.
> >
> > However, what is the real behavior?
> >
> > BinaryReader : Is this designed to read system/hardware supported
> > endian of will always read little endian no matter the system?
> >
> > BinaryWriter: Is this designed to always write little endian binary or
> > it depends on the system?
> >
> > I wish to know in order to extend these classes.
> >
> > BTW, anyone got extends to support big endian binary files?
> >
> > Best regards,
> > Paul.
> >

>
>


 
Reply With Quote
 
Eric Newton
Guest
Posts: n/a
 
      11th Feb 2004
thats an incorrect assumption to make.

there's far more precedent in networking that writes (little endian first) i
think... its whatever the opposite of intel's in-memory byte ordering is.

this is because IP was designed and rolled out on unix boxes, and ironically
all the microsoft IIS servers have to do the byte-flip everytime they encode
byte arrays from a socket


--
Eric Newton
eric.at.ensoft-software.com
www.ensoft-software.com
C#/ASP.net Solutions developer

"Paul Selormey" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> .NET is mainly designed for Windows and could be assumed to
> work with only little endian binary files.
>
> However, what is the real behavior?
>
> BinaryReader : Is this designed to read system/hardware supported
> endian of will always read little endian no matter the system?
>
> BinaryWriter: Is this designed to always write little endian binary or
> it depends on the system?
>
> I wish to know in order to extend these classes.
>
> BTW, anyone got extends to support big endian binary files?
>
> Best regards,
> Paul.
>



 
Reply With Quote
 
Michel Gallant
Guest
Posts: n/a
 
      11th Feb 2004
Basically that is correct. The BinaryWriters write multi-bytes
as little-endian ordered. E.g. Win .wav files write multi-byte
samples in little-endian order. Reading these types of files from
Java requires reversing the data.
Compare to write methods on Java that write data in big-endian ordered fashion.

However, .NET doesn't *always* write multi-byte data out in little-endian
ordering. To "bow" to the majority of the crypt community, many parameters
(like RSA key properties) are created internally and reordered to big-endian
ordered byte[]

- Michel Gallant
MVP Security

"Paul Selormey" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> So, for the .NET framework implemented by Microsoft for the
> Windows, what is the picture like? (could not find any hint in the
> documents)
>
> Best regards,
> Paul.
>
>
> <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Thats implementation specific for the runtime ported to whatever

> underlaying
> > platform shouldnt it?
> >
> >
> > "Paul Selormey" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > .NET is mainly designed for Windows and could be assumed to
> > > work with only little endian binary files.
> > >
> > > However, what is the real behavior?
> > >
> > > BinaryReader : Is this designed to read system/hardware supported
> > > endian of will always read little endian no matter the system?
> > >
> > > BinaryWriter: Is this designed to always write little endian binary or
> > > it depends on the system?
> > >
> > > I wish to know in order to extend these classes.
> > >
> > > BTW, anyone got extends to support big endian binary files?
> > >
> > > Best regards,
> > > Paul.
> > >

> >
> >

>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      11th Feb 2004
Michel Gallant <(E-Mail Removed)> wrote:
> Basically that is correct. The BinaryWriters write multi-bytes
> as little-endian ordered.


Well, the ones in the Windows version of .NET do. However, the
documentation doesn't specify which endianness is used, and there is
precedent for it being system-specific - look at BitConverter.

One of these days, I'll get round to writing a version of
BinaryReader/BinaryWriter which takes an endianness as its parameter...
and likewise BitConverter.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Michel Gallant
Guest
Posts: n/a
 
      11th Feb 2004
"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Michel Gallant <(E-Mail Removed)> wrote:
> > Basically that is correct. The BinaryWriters write multi-bytes
> > as little-endian ordered.

>
> Well, the ones in the Windows version of .NET do. However, the
> documentation doesn't specify which endianness is used, and there is ...


Not exactly true. Although not mentioned everywhere, the endian-ness info
is peppered thoughout the .NET docs. e.g. for BinaryWriter.Write(Int32):

http://msdn.microsoft.com/library/de...riteTopic9.asp

"BinaryWriter stores this data type in little endian format."

- Mitch Gallant






 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      12th Feb 2004
Michel Gallant <(E-Mail Removed)> wrote:
> > Well, the ones in the Windows version of .NET do. However, the
> > documentation doesn't specify which endianness is used, and there is ...

>
> Not exactly true. Although not mentioned everywhere, the endian-ness info
> is peppered thoughout the .NET docs. e.g. for BinaryWriter.Write(Int32):
>
> http://msdn.microsoft.com/library/de...ry/en-us/cpref
> /html/frlrfSystemIOBinaryWriterClassWriteTopic9.asp
>
> "BinaryWriter stores this data type in little endian format."


Oh yes - apologies, I must have missed that before...

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance issues with BinaryReader/BinaryWriter Paul Steele Microsoft C# .NET 4 3rd Feb 2005 07:33 PM
MemoryStreams/BinaryReader/BinaryWriter Claire Microsoft C# .NET 1 9th Jul 2004 03:41 PM
BinaryReader / BinaryWriter possible bug Klaus Petersen Microsoft Dot NET Framework 1 27th May 2004 04:56 PM
IDisposable not implemented in BinaryReader and BinaryWriter? Brane Brodnik Microsoft Dot NET Compact Framework 1 9th Mar 2004 10:02 PM
BinaryWriter.Seek() vs BinaryWriter.BaseStream.Seek() Daniel Goldman Microsoft Dot NET Framework 6 30th Aug 2003 08:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 AM.