Backwards Binary Reader?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I've just tried the following code

FileStream objFS = new FileStream(strFileName, FileMode.Open, FileAccess.Read)
BinaryReader objReader = new BinaryReader(objFS)

UInt32 intFirst = objReader.ReadUInt32()
UInt32 intSecond = 0xC5B8FF00

Now I know that the first four bytes in the file are C5 B8 FF 00 in that order, but when I compare intFirst with intSecond they don't match. On further investigation, intFirst contains 00FFB8C5. WTF?!?

Why is the Binary Reader reading the bytes in backwards? Is there a simple way to switch them the right way, or force the Binary Reader to read them properly

Burns x
 
Burns said:
I've just tried the following code:

FileStream objFS = new FileStream(strFileName, FileMode.Open,
FileAccess.Read);
BinaryReader objReader = new BinaryReader(objFS);

UInt32 intFirst = objReader.ReadUInt32();
UInt32 intSecond = 0xC5B8FF00;

Now I know that the first four bytes in the file are C5 B8 FF 00 in
that order, but when I compare intFirst with intSecond they don't
match. On further investigation, intFirst contains 00FFB8C5. WTF?!?!

Why is the Binary Reader reading the bytes in backwards? Is there a
simple way to switch them the right way, or force the Binary Reader
to read them properly?

It's reading them in little-endian order, as documented (admittedly
somewhat poorly).

Now, what wrote the file, and which endianness was it using (assuming
that the first four bytes are indeed meant to be an unsigned integer)?
 
I'm trying to read the Outlook Express DBX files, so I'm not sure which way it was written. Shall I assume that because Microsoft write both .NET and OE, that they both work with endianness

Burns
 
Burns said:
I'm trying to read the Outlook Express DBX files, so I'm not sure
which way it was written. Shall I assume that because Microsoft write
both .NET and OE, that they both work with endianness?

It's likely, but you really need to find a detailed specification for
the DBX format. Having had a quick look on wotsit.org, it looks like it
is indeed little-endian.
 
Cheers. The only spec I can find on the DBX format is far from detailed, but I'm trying to figure my way through it.
 
Back
Top