BitConverter.ToBoolean メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BitConverter.ToBoolean メソッドの意味・解説 

BitConverter.ToBoolean メソッド

バイト配列内の指定位置にある 1 バイトから変換されブール値を返します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function ToBoolean
 ( _
    value As Byte(), _
    startIndex As Integer _
) As Boolean
Dim value As Byte()
Dim startIndex As Integer
Dim returnValue As Boolean

returnValue = BitConverter.ToBoolean(value, startIndex)
public static bool ToBoolean
 (
    byte[] value,
    int startIndex
)
public:
static bool ToBoolean (
    array<unsigned char>^ value, 
    int startIndex
)
public static boolean ToBoolean (
    byte[] value, 
    int startIndex
)
public static function ToBoolean
 (
    value : byte[], 
    startIndex : int
) : boolean

パラメータ

value

バイト配列

startIndex

value 内の開始位置

戻り値
valuestartIndex にあるバイトが 0 以外の場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

valuenull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

startIndex が 0 未満か、value長さから 1 を引いたより大きい値です。

使用例使用例

ToBoolean メソッド使用してByte 配列要素Boolean 値に変換するコード例次に示します

' Example of the BitConverter.ToBoolean method.
Imports System
Imports Microsoft.VisualBasic

Module BytesToBoolDemo

    Const formatter As String
 = "{0,5}{1,16}{2,10}"
 
    ' Convert a Byte array element to Boolean and display it.
    Sub BAToBool( bytes( ) As Byte,
 index As Integer )

        Dim value As Boolean
 = BitConverter.ToBoolean( bytes, index )

        Console.WriteLine( formatter, index, _
            BitConverter.ToString( bytes, index, 1 ), value )
    End Sub 
       
    Sub Main( )
        Dim byteArray as Byte(
 ) = _
            { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 }

        Console.WriteLine( _
            "This example of the BitConverter.ToBoolean( Byte(
 ), " & _
            "Integer ) " & vbCrLf & "method
 generates the " & _
            "following output. It converts elements of "
 & vbCrLf & _
            "a Byte array to Boolean values." &
 vbCrLf )
        Console.WriteLine( "initial Byte array" )
        Console.WriteLine( "------------------" )
        Console.WriteLine( BitConverter.ToString( byteArray ) )
        Console.WriteLine( )
        Console.WriteLine( formatter, "index", "array
 element", "Boolean" )
        Console.WriteLine( formatter, "-----", "-------------",
 "-------" )
          
        ' Convert Byte array elements to Boolean values.
        BAToBool( byteArray, 0 )
        BAToBool( byteArray, 1 )
        BAToBool( byteArray, 3 )
        BAToBool( byteArray, 5 )
        BAToBool( byteArray, 8 )
        BAToBool( byteArray, 9 )
    End Sub 
End Module

' This example of the BitConverter.ToBoolean( Byte( ), Integer )
' method generates the following output. It converts elements of
' a Byte array to Boolean values.
' 
' initial Byte array
' ------------------
' 00-01-02-04-08-10-20-40-80-FF
' 
' index   array element   Boolean
' -----   -------------   -------
'     0              00     False
'     1              01      True
'     3              04      True
'     5              10      True
'     8              80      True
'     9              FF      True
// Example of the BitConverter.ToBoolean method.
using System;

class GetBytesBoolDemo
{
    const string formatter = "{0,5}{1
,16}{2,10}";
 
    // Convert a byte array element to bool and display it.
    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(
            "This example of the BitConverter.ToBoolean( byte[ ], " +
            "int ) \nmethod generates the following output.
 It " +
            "converts elements \nof a byte array to bool
 values.\n" );
        Console.WriteLine( "initial byte array" );
        Console.WriteLine( "------------------" );
        Console.WriteLine( BitConverter.ToString( byteArray ) + '\n' );
        Console.WriteLine( formatter, "index", "array element",
 "bool" );
        Console.WriteLine( formatter, "-----", "-------------",
 "----" );
          
        // 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( byte[ ], int )
method generates the following output. It converts elements
of a byte array to bool values.

initial byte 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
*/
// 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
*/
// Example of the BitConverter.ToBoolean method.
import System.*;

class GetBytesBoolDemo
{
    private static String formatter = "{0
,5}{1,16}{2,10}";

    // Convert a byte array element to bool and display it.
    public static void BAToBool(ubyte
 bytes[], int index)
    {
        boolean value = BitConverter.ToBoolean(bytes, index);
        Console.WriteLine(formatter, (Int32)index, 
            BitConverter.ToString(bytes, index, 1), (System.Boolean)value);
    } //BAToBool

    public static void main(String[]
 args)
    {
        ubyte byteArray[] =  { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };

        Console.WriteLine(("This example of the "
            + "BitConverter.ToBoolean( byte[ ], int ) \n"
            + "method generates the following output." 
            + " It converts elements \nof a byte array to bool
 values.\n"));
        Console.WriteLine("initial byte array");
        Console.WriteLine("------------------");
        Console.WriteLine((BitConverter.ToString(byteArray) + '\n'));
        Console.WriteLine(formatter, "index", "array element",
 "bool");
        Console.WriteLine(formatter, "-----", "-------------",
 "----");

        // 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);
    } //main
} //GetBytesBoolDemo

/*
This example of the BitConverter.ToBoolean( byte[ ], int )
method generates the following output. It converts elements
of a byte array to bool values.

initial byte 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
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からBitConverter.ToBoolean メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からBitConverter.ToBoolean メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からBitConverter.ToBoolean メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

BitConverter.ToBoolean メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



BitConverter.ToBoolean メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS