Convert one byte at a specified position in a byte array to bool
using System;
class GetBytesBoolDemo
{
const string formatter = "{0,5}{1,16}{2,10}";
public static void BAToBool( byte[ ] bytes, int index )
{
bool value = BitConverter.ToBoolean( bytes, index );
Console.WriteLine( formatter, index, BitConverter.ToString( bytes, index, 1 ), value );
}
public static void Main( )
{
byte[ ] byteArray = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
Console.WriteLine( BitConverter.ToString( byteArray ) + '\n' );
BAToBool( byteArray, 0 );
BAToBool( byteArray, 1 );
}
}
Related examples in the same category