Iam trying to pack some bits and create a client request packet using a
Byte[] array. To test the "endianess" I tried a small sample and used the
BitConverter to print the actual values ... and the out does not seem right
..... the sample code and the output is shown below.
What Am I missing here ?
using System;
....
byte b = 10;
uint val = b;
Byte[] packet = BitConverter.GetBytes(b);
BitArray array = new
BitArray(packet);
IEnumerator enumerator = array.GetEnumerator();
string value = null;
int width = 8;
if(BitConverter.IsLittleEndian)
Console.WriteLine("Little Endian order.");
else
Console.WriteLine("Big Endian order.");
while(enumerator.MoveNext())
{
if(width == 0)
{
Console.Write(" ");
width = 8;
}
value = (enumerator.Current.ToString() == Boolean.TrueString)?"1":"0";
Console.Write(value);
width--;
}
Output
=========
Little Endian order.
01010000 00000000