title: Controlling bits in a ushort array
body: <p>I would like to know how I can read and write specific bits efficiently to a ushort integer.</p>
  
  <p>The methods would be something like so:</p>
  
  <pre><code>// Sets the bit positioned at bitNumber in the ushort integer b
  // to be either 1 or 0 depending on state.
  public ushort SetBit(ushort b, int bitNumber, bool state)
  {
     ushort result = b;
     // Code to set the specific bit in ushort result.
     return result
  }
  // Returns the value of the bit in position bitNumber from the 
  // ushort b as a true or false.
  public bool GetBit(ushort b, int bitNumber)
  {
     bool stateOfBit = false;
     // Code to read the bit into stateOfBit.
     return stateOfBit;
  }
  </code></pre>
  
  <p>I have tried using BitArray class but it only takes a byte or a 32 bit integer.</p>
  
  <p>Does someone know how to do this?</p>
  
  <p>Thanks</p>