views:

118

answers:

1

Possible Duplicate:
byte[] array pattern search

I am trying to write a simple compression algorthm in C# and .NET 3.5 and I need to be able to search a particular file for occurrences of a certain sequence of bits. what is the fastest way of doing this?

+1  A: 

Since the file is 8K I would start by reading all the bytes into an in memory array like this:

byte[] bytes = System.IO.File.ReadAllBytes(fileName);

There is a code sample to search in this stack overflow entry:

http://stackoverflow.com/questions/283456/byte-array-pattern-search

John JJ Curtis
I'm not looking for text in a binary file. Rather, I'm looking for a sequence of bits in a file. If it matters, the file will be 8 kilobytes in size.
RCIX
How large of a sequence of bits?
John JJ Curtis
I might have been unclear: i am searching within an 8KB file for up to 128 bytes at a time it looks like.
RCIX
Was the new stack overflow link I provided helpful?
John JJ Curtis
Sort of. I'm looking for the simplest way to do so, not the fastest way.
RCIX
see http://stackoverflow.com/questions/1020438/c-array-subset-fetching for a better description of what i need.
RCIX
The function in that link is pretty darn simple, is it too slow for you?
John JJ Curtis
Nope, it worked.
RCIX