C# BitConverter ToBoolean
Description
BitConverter ToBoolean
returns a Boolean value converted
from one byte at a specified position in a byte array.
Syntax
BitConverter.ToBoolean
has the following syntax.
public static bool ToBoolean(
byte[] value,
int startIndex
)
Parameters
BitConverter.ToBoolean
has the following parameters.
value
- An array of bytes.startIndex
- The starting position within value.
Returns
BitConverter.ToBoolean
method returns true if the byte at startIndex in value is nonzero; otherwise, false.
Example
The following code example converts elements of Byte arrays to Boolean values with the ToBoolean method.
/*w w w .j a v a2 s .c om*/
using System;
class GetBytesBoolDemo
{
public static void Main( )
{
byte[ ] bytes = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
bool value = BitConverter.ToBoolean( bytes, 0 );
Console.WriteLine( value );
}
}
The code above generates the following result.