BinaryReader and BinaryWriter and Endianess

  • Thread starter Thread starter Paul Selormey
  • Start date Start date
P

Paul Selormey

..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.
 
Thats implementation specific for the runtime ported to whatever underlaying
platform shouldnt it?
 
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.
 
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
 
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
 
Michel Gallant said:
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.
 
Back
Top