title: Convert from BitArray to Byte
body: <p>I have a <a href="https://msdn.microsoft.com/en-us/library/system.collections.bitarray(v=vs.110).aspx" rel="noreferrer"><code>BitArray</code></a> with the length of 8, and I need a function to convert it to a <code>byte</code>. How to do it?</p>
  
  <p>Specifically, I need a correct function of <code>ConvertToByte</code>:</p>
  
  <pre><code>BitArray bit = new BitArray(new bool[]
  {
      false, false, false, false,
      false, false, false, true
  });
  
  //How to write ConvertToByte
  byte myByte = ConvertToByte(bit);
  var recoveredBit = new BitArray(new[] { myByte });
  Assert.AreEqual(bit, recoveredBit);
  </code></pre>