469,639 Members | 1,579 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,639 developers. It's quick & easy.

Backwards Binary Reader?

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
Nov 16 '05 #1
4 2503
Burns <an*******@discussions.microsoft.com> wrote:
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)?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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
Nov 16 '05 #3
Burns <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
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.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by flat_ross | last post: by
6 posts views Thread by Neil Patel | last post: by
12 posts views Thread by Adam J. Schaff | last post: by
6 posts views Thread by james | last post: by
1 post views Thread by young_leaf | last post: by
11 posts views Thread by Gina_Marano | last post: by
6 posts views Thread by =?Utf-8?B?VGhvbWFzWg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.