I'm trying to convert a byte array to a string in binary format, but Convert.ToString() returns unexpected results. Can you please tell me what am I doing wrong? Here is the code:
class Program
{
static void Main(string[] args)
{
StringBuilder str = new StringBuilder();
byte[] x = { 0xB1, 0x53, 0x63 };
for (int i = 0; i < 3; i++)
{
str.Append(Convert.ToString(x[i], 2));
}
Console.WriteLine(str);
Console.ReadLine();
}
}
The output is:
1011000110100111100011
I expected the output to be:
1011_0001_0101_0011_0110_0011 (0xB15363)
And not:
1011_0001_1010_0111_1000_11