views:

66

answers:

1

Hi, I'm trying to write a simple reader for AutoCAD's DWG files in .NET. I don't actually need to access all data in the file so the complexity that would otherwise be involved in writing a reader/writer for the whole file format is not an issue.

I've managed to read in the basics, such as the version, all the header data, the section locator records, but am having problems with reading the actual sections.

The problem seems to stem from the fact that the format uses a custom method of storing some data types. I'm going by the specs here:

http://www.opendesign.com/files/guestdownloads/OpenDesign_Specification_for_.dwg_files.pdf

Specifically, the types that depend on reading in of individual bits are the types I'm struggling to read. A large part of the problem seems to be that C#'s BinaryReader only lets you read in whole bytes at a time, when in fact I believe I need the ability to read in individual bits and not simply 8 bits or a multiple of at a time.

It could be that I'm misunderstanding the spec and how to interpret it, but if anyone could clarify how I might go about reading in individual bits from a stream, or even how to read in some of the variables types in the above spec that require more complex manipulation of bits than simply reading in full bytes then that'd be excellent.

I do realise there are commercial libraries out there for this, but the price is simply too high on all of them to be justifiable for the task at hand.

Any help much appreciated.

+1  A: 

You can always use BitArray class to do bit wise manipulation. So you read bytes from file and load them into BitArray and then access individual bits.

VinayC