[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Reading data, of which bit sizes are not multiples of 8.

Posted on 2004-10-21
4
Medium Priority
?
206 Views
Last Modified: 2008-03-03
Ok, I am familiar with the BinaryReader class, and it's plethora of supported data formats

yet it is still very limited to what I need to do.

EXPERTS, what do you think is the best way, in .Net, to read and write 9,10,11 and especially 12 bit data.


My first inclination seems like a hack.  Where I would read data in 16-bit words, and perform bit masking on the data for each acquired value.  I'm sure that would work, but there's gotta be a better way.
0
Comment
Question by:Tertioptus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12374124
Have a look to this class, maybe could be helpful:
http://www.codeproject.com/cpp/XBitArray.asp
Good luck,
Jaime.
0
 

Expert Comment

by:SuperCableMan
ID: 12377068
Why not try using a bitfield or some fancy union? Then use a memcpy directly into the struct / union?

typedef struct EIGHTBITVAL
{
   unsigned char bit1 :1;
   unsigned char bit2 :1;
  ...
   unsigned char bit8 :1;
}EightBit_t;

typedef struct 10BITVAL
{
   unsigned char bit1  :1;
   ...
   unsigned char bit10 :1;
}TenBit_t;

typedef struct ODDSIZEVALUE
{
    union
    {
       struct 8
       {
           EightBit eight;
       }
       struct 10
       {
           TenBit_t  ten;
        };
       ....
       unsigned char workWithThisOne;
    }
}

Struct'ing it out like that might help.  Using that char at the end of the union will allow you to do whatever math you need to do, then switch between the types (because of the union) as necesary.  You may have some more overhead in keeping track of what size (8,9,10 bit value) but i hope that helps.
0
 
LVL 5

Author Comment

by:Tertioptus
ID: 12377099
Im sorry.  I'm looking for c# code.
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 180 total points
ID: 12377144
Have you seen the BitArray class from .Net framework?

it is located in the System.Collections namespace.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question