title: BinaryReader - Reading a Single " BIT "?
body: <p><strong>Case :</strong><br>
  Again trying to capture packets through my NIC,<br>
  I have developed 2 Extensions to use in capturing variable number of bits  </p>
  
  <pre><code>    public static string ReadBits ( this BinaryReader Key , int Value )
      {
          BitArray _BitArray = new BitArray ( Value );
  
          for ( int Loop = 0 ; Loop &gt; Value ; Loop++ )
          {
  /* Problem HERE ---&gt; */   _BitArray [ Loop ] = Key . ReadBoolean ( );
          }
  
          return BitConverter . ToString ( _BitArray . ToByteArray ( ) );
      }
  
      public static byte [ ] ToByteArray ( this BitArray Key )
      {
          byte [ ] Value = new byte [ ( int ) Math . Ceiling ( ( double ) Key . Length / 8 ) ];
          Key . CopyTo ( Value , 0 );
          return Value;
      }
  </code></pre>
  
  <p><strong>Problem :</strong>  </p>
  
  <pre><code>_BitArray [ Loop ] = Key . ReadBoolean ( );  
  </code></pre>
  
  <p>As I'm trying to read single bits, but referring to <a href="http://msdn.microsoft.com/en-us/library/system.io.binaryreader.readboolean.aspx" rel="nofollow">MSDN Documentation</a>,<br>
   It advances the stream position by 1 BYTE not 1 BIT !!!  </p>
  
  <blockquote>
    <p>Reads a Boolean value from the current stream and advances the current
    position of the stream by one <strong>byte</strong>.  </p>
  </blockquote>
  
  <p><strong>Question :</strong><br>
  Can I really capture "ONLY" 1 Bit &amp; advance the stream position by 1 Bit ?<br>
  Please suggest me solutions or ideas :)  </p>
  
  <p>Regards,</p>