This documentation is archived and is not being maintained.
BitConverter::ToBoolean Method
Visual Studio 2010
Returns a Boolean value converted from one byte at a specified position in a byte array.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: array<System::Byte>
An array of bytes.
- startIndex
- Type: System::Int32
The starting position within value.
Return Value
Type: System::Booleantrue if the byte at startIndex in value is nonzero; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is nullptr. |
| ArgumentOutOfRangeException | startIndex is less than zero or greater than the length of value minus 1. |
The following code example converts elements of Byte arrays to Boolean values with the ToBoolean method.
// Example of the BitConverter::ToBoolean method. using namespace System; // Convert a byte array element to bool and display it. void BAToBool( array<unsigned char>^bytes, int index ) { bool value = BitConverter::ToBoolean( bytes, index ); Console::WriteLine( "{0,5}{1,16}{2,10}", index, BitConverter::ToString( bytes, index, 1 ), value ); } int main() { array<unsigned char>^byteArray = {0,1,2,4,8,16,32,64,128,255}; Console::WriteLine( "This example of the BitConverter::ToBoolean( unsigned " "char[ ], int ) \nmethod generates the following output. It " "converts elements of a \nbyte array to bool values.\n" ); Console::WriteLine( "initial unsigned char array" ); Console::WriteLine( "---------------------------" ); Console::WriteLine( BitConverter::ToString( byteArray ) ); Console::WriteLine(); Console::WriteLine( "{0,5}{1,16}{2,10}", "index", "array element", "bool" ); Console::WriteLine( "{0,5}{1,16}{2,10}", "-----", "-------------", "----" ); // Convert byte array elements to bool values. BAToBool( byteArray, 0 ); BAToBool( byteArray, 1 ); BAToBool( byteArray, 3 ); BAToBool( byteArray, 5 ); BAToBool( byteArray, 8 ); BAToBool( byteArray, 9 ); } /* This example of the BitConverter::ToBoolean( unsigned char[ ], int ) method generates the following output. It converts elements of a byte array to bool values. initial unsigned char array --------------------------- 00-01-02-04-08-10-20-40-80-FF index array element bool ----- ------------- ---- 0 00 False 1 01 True 3 04 True 5 10 True 8 80 True 9 FF True */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: