title: BitArray(16) to HexString
body: <p>I'm trying to convert a BitArray to a Hex String</p>
  <p>My test BitArray is &quot;0000001010000000&quot; and it should return &quot;02 80&quot; in Hex</p>
  <p>Tried the following:</p>
  <pre><code>BitArray b = new BitArray(16);
  b.Set(7, true);
  b.Set(9, true);
  </code></pre>
  <p>Then, by examining the BitArray object I created and do get the 640 decimal value that corresponds to that binary string.</p>
  <p>But I can't find the way to convert that to Hex.</p>
  <p>I'm avoiding working with Byte Array which is a different class.</p>
  <p>This works, but it's kind of complicated I'm sure there must be an easier way and I can't understand why I must switch the values.</p>
  <pre><code>byte[] bytes = new byte[2];
  b.CopyTo(bytes, 0);
  string Retorno = BitConverter.ToString(bytes);
  string[] auxstr = Retorno.Split('-');
  Retorno = auxstr[1] + &quot;-&quot; + auxstr[0];
  </code></pre>
  <p>Any advice?</p>