473,471 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2801
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: flat_ross | last post by:
If there was one thing nice about "Binary Compatibility" in VB6, it would tell you at compile time that you changed your public interface. I am looking for the same functionality in .NET. I know...
6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
6
by: james | last post by:
I will try to make this short and to the point. I am reading values from a file using a Binary Reader. At a particular address I can get a value of , Hex 10 or Hex 01 . (varies can be 30, 20, 02,03...
1
by: young_leaf | last post by:
Hi, What is the most efficient way of making a Binary File Reader, which reads binary file on command of other application. The program: a) Read Binary File b) Create a Table of data based on...
11
by: Gina_Marano | last post by:
Hey all, I need to validate a large binary file. I just need to read the last 100 or so bytes of the file. Here is what I am currently doing but it seems slow: private bool ValidFile(string...
6
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
4
by: Russell Mangel | last post by:
Hi, The code I have posted searches for a pattern of bytes starting from the end of Byte array *backwords*, if a match is found, return the starting index of those found bytes. Since one of...
20
by: tomPee | last post by:
Hi, I've bumbed into a slight problem now, and I just don't seem to know how to fix it. What I want to do is the following: Send over a socket: 1. Number of files to be send (not as an integer,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.