title: Bit fields in C#
body: <p>I have a structure which I need to populate and write to disk (several actually).</p>
  
  <p>An example is:</p>
  
  <pre><code>byte-6    
  bit0 - original_or_copy  
  bit1 - copyright  
  bit2 - data_alignment_indicator  
  bit3 - PES_priority  
  bit4-bit5 - PES_scrambling control.  
  bit6-bit7 - reserved  
  </code></pre>
  
  <p>In C I might do something like the following:</p>
  
  <pre><code>struct PESHeader  {
      unsigned reserved:2;
      unsigned scrambling_control:2;
      unsigned priority:1;
      unsigned data_alignment_indicator:1;
      unsigned copyright:1;
      unsigned original_or_copy:1;
  };
  </code></pre>
  
  <p>Is there any way to do this in C# that would enable me to access the bits using the struct dereferencing dot operator? </p>
  
  <p>For a couple of structures, I can just do bit shifting wrapped in an accessor function.</p>
  
  <p>I have loads of structures to handle in this way, so I'm looking for something that's easier to read and quicker to write.</p>