I'm trying to convert a BitArray to a Hex String
My test BitArray is "0000001010000000" and it should return "02 80" in Hex
Tried the following:
BitArray b = new BitArray(16);
b.Set(7, true);
b.Set(9, true);
Then, by examining the BitArray object I created and do get the 640 decimal value that corresponds to that binary string.
But I can't find the way to convert that to Hex.
I'm avoiding working with Byte Array which is a different class.
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.
byte[] bytes = new byte[2];
b.CopyTo(bytes, 0);
string Retorno = BitConverter.ToString(bytes);
string[] auxstr = Retorno.Split('-');
Retorno = auxstr[1] + "-" + auxstr[0];
Any advice?