BitVector32 構造体とは? わかりやすく解説

BitVector32 構造体

ブール値と小さ整数メモリ32 ビット格納する単純な構造体提供します

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

public struct BitVector32
public value class BitVector32
public final class BitVector32 extends ValueType
JScript では、構造体使用できますが、新規に宣言することはできません。
解説解説

内部的に使用されるブール値と小さ整数に対しては、BitArray よりも BitVector32使用した方が効率的です。BitArray必要に応じてサイズ無制限に大きくできますが、クラス インスタンス必要なメモリおよびパフォーマンスオーバーヘッドあります。それに対してBitVector3232 ビットしか使用しません。

BitVector32 構造体は、小さ整数のためのセクションまたはブール値のためのビット フラグいずれか格納するよう設定できますが、その両方格納できません。BitVector32.Section は BitVector32 内のウィンドウで、CreateSection で指定した最大値格納できる最小数の連続ビットから構成されます。たとえば、最大値が 1 のセクション1 ビットだけで構成され最大値が 5 のセクションは 3 ビット構成されます。ブール値として機能する最大値 1 で BitVector32.Section作成して、同じ BitVector32整数ブール値を格納できます

メンバには、BitVector32セクションとして設定されている場合使用できるものと、ビット フラグとして設定されている場合使用できるものがあります。たとえば、BitVector32.Item プロパティは、セクションとして設定されBitVector32インデクサであり、BitVector32.Item プロパティは、ビット フラグとして設定されBitVector32インデクサです。CreateMask は、ビット フラグとして設定されBitVector32 内の個別ビットアクセスするために使用できる一連のマスク作成します

セクションとして設定されBitVector32マスク使用すると、予期しない結果生じることがあります

使用例使用例

次のコード例では、BitVector32ビット フラグコレクションとして使用してます。

Imports System
Imports System.Collections.Specialized

Public Class SamplesBitVector32

   Public Shared Sub Main()

      ' Creates and initializes a BitVector32 with all bit flags set
 to FALSE.
      Dim myBV As New BitVector32(0)

      ' Creates masks to isolate each of the first five bit flags.
      Dim myBit1 As Integer
 = BitVector32.CreateMask()
      Dim myBit2 As Integer
 = BitVector32.CreateMask(myBit1)
      Dim myBit3 As Integer
 = BitVector32.CreateMask(myBit2)
      Dim myBit4 As Integer
 = BitVector32.CreateMask(myBit3)
      Dim myBit5 As Integer
 = BitVector32.CreateMask(myBit4)

      ' Sets the alternating bits to TRUE.
      Console.WriteLine("Setting alternating bits to TRUE:")
      Console.WriteLine("   Initial:         {0}",
 myBV.ToString())
      myBV(myBit1) = True
      Console.WriteLine("   myBit1 = TRUE:   {0}",
 myBV.ToString())
      myBV(myBit3) = True
      Console.WriteLine("   myBit3 = TRUE:   {0}",
 myBV.ToString())
      myBV(myBit5) = True
      Console.WriteLine("   myBit5 = TRUE:   {0}",
 myBV.ToString())
   End Sub 'Main 
End Class 'SamplesBitVector32


' This code produces the following output.
'
' Setting alternating bits to TRUE:
'    Initial:         BitVector32{00000000000000000000000000000000}
'    myBit1 = TRUE:   BitVector32{00000000000000000000000000000001}
'    myBit3 = TRUE:   BitVector32{00000000000000000000000000000101}
'    myBit5 = TRUE:   BitVector32{00000000000000000000000000010101}

using System;
using System.Collections.Specialized;


public class SamplesBitVector32  {

   public static void Main()
  {

      // Creates and initializes a BitVector32 with all bit flags set
 to FALSE.
      BitVector32 myBV = new BitVector32( 0 );

      // Creates masks to isolate each of the first five bit flags.
      int myBit1 = BitVector32.CreateMask();
      int myBit2 = BitVector32.CreateMask( myBit1 );
      int myBit3 = BitVector32.CreateMask( myBit2 );
      int myBit4 = BitVector32.CreateMask( myBit3 );
      int myBit5 = BitVector32.CreateMask( myBit4 );

      // Sets the alternating bits to TRUE.
      Console.WriteLine( "Setting alternating bits to TRUE:" );
      Console.WriteLine( "   Initial:         {0}", myBV.ToString() );
      myBV[myBit1] = true;
      Console.WriteLine( "   myBit1 = TRUE:   {0}", myBV.ToString() );
      myBV[myBit3] = true;
      Console.WriteLine( "   myBit3 = TRUE:   {0}", myBV.ToString() );
      myBV[myBit5] = true;
      Console.WriteLine( "   myBit5 = TRUE:   {0}", myBV.ToString() );

   }

}

/*
This code produces the following output.

Setting alternating bits to TRUE:
   Initial:         BitVector32{00000000000000000000000000000000}
   myBit1 = TRUE:   BitVector32{00000000000000000000000000000001}
   myBit3 = TRUE:   BitVector32{00000000000000000000000000000101}
   myBit5 = TRUE:   BitVector32{00000000000000000000000000010101}


*/
#using <system.dll>

using namespace System;
using namespace System::Collections::Specialized;
int main()
{
   
   // Creates and initializes a BitVector32 with all bit flags set to
 FALSE.
   BitVector32 myBV(0);
   
   // Creates masks to isolate each of the first five bit flags.
   int myBit1 = BitVector32::CreateMask();
   int myBit2 = BitVector32::CreateMask( myBit1 );
   int myBit3 = BitVector32::CreateMask( myBit2 );
   int myBit4 = BitVector32::CreateMask( myBit3 );
   int myBit5 = BitVector32::CreateMask( myBit4 );
   
   // Sets the alternating bits to TRUE.
   Console::WriteLine( "Setting alternating bits to TRUE:" );
   Console::WriteLine( "   Initial:       {0}", myBV );
   myBV[ myBit1 ] = true;
   Console::WriteLine( "   myBit1 = TRUE: {0}", myBV );
   myBV[ myBit3 ] = true;
   Console::WriteLine( "   myBit3 = TRUE: {0}", myBV );
   myBV[ myBit5 ] = true;
   Console::WriteLine( "   myBit5 = TRUE: {0}", myBV );
}

/*
This code produces the following output.

Setting alternating bits to TRUE:
Initial:         BitVector32 {00000000000000000000000000000000}
myBit1 = TRUE:   BitVector32 {00000000000000000000000000000001}
myBit3 = TRUE:   BitVector32 {00000000000000000000000000000101}
myBit5 = TRUE:   BitVector32 {00000000000000000000000000010101}


*/
import System.*;
import System.Collections.Specialized.*;

public class SamplesBitVector32
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a BitVector32 with all bit flags set
 to FALSE.
        BitVector32 myBV = new BitVector32(0);
      
        // Creates masks to isolate each of the first five bit flags.
        int myBit1 = BitVector32.CreateMask();
        int myBit2 = BitVector32.CreateMask(myBit1);
        int myBit3 = BitVector32.CreateMask(myBit2);
        int myBit4 = BitVector32.CreateMask(myBit3);
        int myBit5 = BitVector32.CreateMask(myBit4);
          
        // Sets the alternating bits to TRUE.
        Console.WriteLine("Setting alternating bits to TRUE:");
        Console.WriteLine("   Initial:         {0}", myBV.ToString());
        myBV.set_Item(myBit1, true);
        Console.WriteLine("   myBit1 = TRUE:   {0}", myBV.ToString());
        myBV.set_Item(myBit3, true);
        Console.WriteLine("   myBit3 = TRUE:   {0}", myBV.ToString());
        myBV.set_Item(myBit5, true);
        Console.WriteLine("   myBit5 = TRUE:   {0}", myBV.ToString());
    } //main
} //SamplesBitVector32

/*
This code produces the following output.

Setting alternating bits to TRUE:
   Initial:         BitVector32{00000000000000000000000000000000}
   myBit1 = TRUE:   BitVector32{00000000000000000000000000000001}
   myBit3 = TRUE:   BitVector32{00000000000000000000000000000101}
   myBit5 = TRUE:   BitVector32{00000000000000000000000000010101}


*/

次のコード例では、BitVector32セクションコレクションとして使用してます。

Imports System
Imports System.Collections.Specialized

Public Class SamplesBitVector32
   
   Public Shared Sub Main()
      
      ' Creates and initializes a BitVector32.
      Dim myBV As New BitVector32(0)
      
      ' Creates four sections in the BitVector32 with maximum values
 6, 3, 1, and 15.
      ' mySect3, which uses exactly one bit, can also be used as a bit
 flag.
      Dim mySect1 As BitVector32.Section =
 BitVector32.CreateSection(6)
      Dim mySect2 As BitVector32.Section =
 BitVector32.CreateSection(3, mySect1)
      Dim mySect3 As BitVector32.Section =
 BitVector32.CreateSection(1, mySect2)
      Dim mySect4 As BitVector32.Section =
 BitVector32.CreateSection(15, mySect3)
      
      ' Displays the values of the sections.
      Console.WriteLine("Initial values:")
      Console.WriteLine(ControlChars.Tab + "mySect1: {0}",
 myBV(mySect1))
      Console.WriteLine(ControlChars.Tab + "mySect2: {0}",
 myBV(mySect2))
      Console.WriteLine(ControlChars.Tab + "mySect3: {0}",
 myBV(mySect3))
      Console.WriteLine(ControlChars.Tab + "mySect4: {0}",
 myBV(mySect4))
      
      ' Sets each section to a new value and displays the value of the
 BitVector32 at each step.
      Console.WriteLine("Changing the values of each section:")
      Console.WriteLine(ControlChars.Tab + "Initial:    "
 + ControlChars.Tab + "{0}", myBV.ToString())
      myBV(mySect1) = 5
      Console.WriteLine(ControlChars.Tab + "mySect1 = 5:"
 + ControlChars.Tab + "{0}", myBV.ToString())
      myBV(mySect2) = 3
      Console.WriteLine(ControlChars.Tab + "mySect2 = 3:"
 + ControlChars.Tab + "{0}", myBV.ToString())
      myBV(mySect3) = 1
      Console.WriteLine(ControlChars.Tab + "mySect3 = 1:"
 + ControlChars.Tab + "{0}", myBV.ToString())
      myBV(mySect4) = 9
      Console.WriteLine(ControlChars.Tab + "mySect4 = 9:"
 + ControlChars.Tab + "{0}", myBV.ToString())
      
      ' Displays the values of the sections.
      Console.WriteLine("New values:")
      Console.WriteLine(ControlChars.Tab + "mySect1: {0}",
 myBV(mySect1))
      Console.WriteLine(ControlChars.Tab + "mySect2: {0}",
 myBV(mySect2))
      Console.WriteLine(ControlChars.Tab + "mySect3: {0}",
 myBV(mySect3))
      Console.WriteLine(ControlChars.Tab + "mySect4: {0}",
 myBV(mySect4))

   End Sub 'Main 

End Class 'SamplesBitVector32


' This code produces the following output.
'
' Initial values:
'        mySect1: 0
'        mySect2: 0
'        mySect3: 0
'        mySect4: 0
' Changing the values of each section:
'        Initial:        BitVector32{00000000000000000000000000000000}
'        mySect1 = 5:    BitVector32{00000000000000000000000000000101}
'        mySect2 = 3:    BitVector32{00000000000000000000000000011101}
'        mySect3 = 1:    BitVector32{00000000000000000000000000111101}
'        mySect4 = 9:    BitVector32{00000000000000000000001001111101}
' New values:
'        mySect1: 5
'        mySect2: 3
'        mySect3: 1
'        mySect4: 9
using System;
using System.Collections.Specialized;


public class SamplesBitVector32  {

   public static void Main()
  {

      // Creates and initializes a BitVector32.
      BitVector32 myBV = new BitVector32( 0 );

      // Creates four sections in the BitVector32 with maximum values
 6, 3, 1, and 15.
      // mySect3, which uses exactly one bit, can also be used as a
 bit flag.
      BitVector32.Section mySect1 = BitVector32.CreateSection( 6 );
      BitVector32.Section mySect2 = BitVector32.CreateSection( 3, mySect1 );
      BitVector32.Section mySect3 = BitVector32.CreateSection( 1, mySect2 );
      BitVector32.Section mySect4 = BitVector32.CreateSection( 15, mySect3 );

      // Displays the values of the sections.
      Console.WriteLine( "Initial values:" );
      Console.WriteLine( "\tmySect1: {0}", myBV[mySect1] );
      Console.WriteLine( "\tmySect2: {0}", myBV[mySect2] );
      Console.WriteLine( "\tmySect3: {0}", myBV[mySect3] );
      Console.WriteLine( "\tmySect4: {0}", myBV[mySect4] );

      // Sets each section to a new value and displays the value of
 the BitVector32 at each step.
      Console.WriteLine( "Changing the values of each section:" );
      Console.WriteLine( "\tInitial:    \t{0}", myBV.ToString() );
      myBV[mySect1] = 5;
      Console.WriteLine( "\tmySect1 = 5:\t{0}", myBV.ToString() );
      myBV[mySect2] = 3;
      Console.WriteLine( "\tmySect2 = 3:\t{0}", myBV.ToString() );
      myBV[mySect3] = 1;
      Console.WriteLine( "\tmySect3 = 1:\t{0}", myBV.ToString() );
      myBV[mySect4] = 9;
      Console.WriteLine( "\tmySect4 = 9:\t{0}", myBV.ToString() );

      // Displays the values of the sections.
      Console.WriteLine( "New values:" );
      Console.WriteLine( "\tmySect1: {0}", myBV[mySect1] );
      Console.WriteLine( "\tmySect2: {0}", myBV[mySect2] );
      Console.WriteLine( "\tmySect3: {0}", myBV[mySect3] );
      Console.WriteLine( "\tmySect4: {0}", myBV[mySect4] );

   }

}

/*
This code produces the following output.

Initial values:
        mySect1: 0
        mySect2: 0
        mySect3: 0
        mySect4: 0
Changing the values of each section:
        Initial:        BitVector32{00000000000000000000000000000000}
        mySect1 = 5:    BitVector32{00000000000000000000000000000101}
        mySect2 = 3:    BitVector32{00000000000000000000000000011101}
        mySect3 = 1:    BitVector32{00000000000000000000000000111101}
        mySect4 = 9:    BitVector32{00000000000000000000001001111101}
New values:
        mySect1: 5
        mySect2: 3
        mySect3: 1
        mySect4: 9

*/
#using <system.dll>

using namespace System;
using namespace System::Collections::Specialized;

int main()
{
   // Creates and initializes a BitVector32.
   BitVector32 myBV(0);

   // Creates four sections in the BitVector32 with maximum values 6,
 3, 1, and 15.
   // mySect3, which uses exactly one bit, can also be used as a bit
 flag.
   BitVector32::Section mySect1 = BitVector32::CreateSection( 6 );
   BitVector32::Section mySect2 = BitVector32::CreateSection( 3, mySect1 );
   BitVector32::Section mySect3 = BitVector32::CreateSection( 1, mySect2 );
   BitVector32::Section mySect4 = BitVector32::CreateSection( 15, mySect3 );

   // Displays the values of the sections.
   Console::WriteLine( "Initial values:" );
   Console::WriteLine( "\tmySect1: {0}", myBV[ mySect1 ] );
   Console::WriteLine( "\tmySect2: {0}", myBV[ mySect2 ] );
   Console::WriteLine( "\tmySect3: {0}", myBV[ mySect3 ] );
   Console::WriteLine( "\tmySect4: {0}", myBV[ mySect4 ] );

   // Sets each section to a new value and displays the value of the
 BitVector32 at each step.
   Console::WriteLine( "Changing the values of each section:" );
   Console::WriteLine( "\tInitial:    \t {0}", myBV );
   myBV[ mySect1 ] = 5;
   Console::WriteLine( "\tmySect1 = 5:\t {0}", myBV );
   myBV[ mySect2 ] = 3;
   Console::WriteLine( "\tmySect2 = 3:\t {0}", myBV );
   myBV[ mySect3 ] = 1;
   Console::WriteLine( "\tmySect3 = 1:\t {0}", myBV );
   myBV[ mySect4 ] = 9;
   Console::WriteLine( "\tmySect4 = 9:\t {0}", myBV );

   // Displays the values of the sections.
   Console::WriteLine( "New values:" );
   Console::WriteLine( "\tmySect1: {0}", myBV[ mySect1 ] );
   Console::WriteLine( "\tmySect2: {0}", myBV[ mySect2 ] );
   Console::WriteLine( "\tmySect3: {0}", myBV[ mySect3 ] );
   Console::WriteLine( "\tmySect4: {0}", myBV[ mySect4 ] );
}

/*
This code produces the following output.

Initial values:
        mySect1: 0
        mySect2: 0
        mySect3: 0
        mySect4: 0
Changing the values of each section:
        Initial:        BitVector32 {00000000000000000000000000000000}
        mySect1 = 5:    BitVector32 {00000000000000000000000000000101}
        mySect2 = 3:    BitVector32 {00000000000000000000000000011101}
        mySect3 = 1:    BitVector32 {00000000000000000000000000111101}
        mySect4 = 9:    BitVector32 {00000000000000000000001001111101}
New values:
        mySect1: 5
        mySect2: 3
        mySect3: 1
        mySect4: 9

*/
import System.*;
import System.Collections.Specialized.*;

public class SamplesBitVector32
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a BitVector32.
        BitVector32 myBV = new BitVector32(0);
      
        // Creates four sections in the BitVector32 with maximum values
 
        // 6, 3, 1, and 15. mySect3, which uses exactly one bit, 
        // can also be used as a bit flag.
        BitVector32.Section mySect1 = BitVector32.CreateSection((short)6);
        BitVector32.Section mySect2 = 
            BitVector32.CreateSection((short)3, mySect1);
        BitVector32.Section mySect3 = 
            BitVector32.CreateSection((short)1, mySect2);
        BitVector32.Section mySect4 = 
            BitVector32.CreateSection((short)15, mySect3);
          
        // Displays the values of the sections.
        Console.WriteLine("Initial values:");
        Console.WriteLine("\tmySect1: {0}", 
            System.Convert.ToString(myBV .get_Item( mySect1)));
        Console.WriteLine("\tmySect2: {0}", 
            System.Convert.ToString(myBV.get_Item( mySect2)));
        Console.WriteLine("\tmySect3: {0}", 
            System.Convert.ToString(myBV.get_Item(mySect3)));
        Console.WriteLine("\tmySect4: {0}", 
            System.Convert.ToString(myBV.get_Item(mySect4)));
          
        // Sets each section to a new value and displays the value of
 the
        // BitVector32 at each step.
        Console.WriteLine("Changing the values of each section:");
        Console.WriteLine("\tInitial:    \t{0}", myBV.ToString());
        myBV.set_Item(mySect1 , 5);
        Console.WriteLine("\tmySect1 = 5:\t{0}", myBV.ToString());
        myBV.set_Item(mySect2 , 3);
        Console.WriteLine("\tmySect2 = 3:\t{0}", myBV.ToString());
        myBV.set_Item(mySect3 , 1);
        Console.WriteLine("\tmySect3 = 1:\t{0}", myBV.ToString());
        myBV.set_Item(mySect4 , 9);
        Console.WriteLine("\tmySect4 = 9:\t{0}", myBV.ToString());
          
        // Displays the values of the sections.
        Console.WriteLine("New values:");
        Console.WriteLine("\tmySect1: {0}", 
            System.Convert.ToString(myBV.get_Item( mySect1)));
        Console.WriteLine("\tmySect2: {0}", 
            System.Convert.ToString(myBV.get_Item(mySect2)));
        Console.WriteLine("\tmySect3: {0}", 
            System.Convert.ToString(myBV.get_Item(mySect3)));
        Console.WriteLine("\tmySect4: {0}", 
            System.Convert.ToString(myBV.get_Item(mySect4)));
    } //main
} //SamplesBitVector32

/*
This code produces the following output.

Initial values:
        mySect1: 0
        mySect2: 0
        mySect3: 0
        mySect4: 0
Changing the values of each section:
        Initial:        BitVector32{00000000000000000000000000000000}
        mySect1 = 5:    BitVector32{00000000000000000000000000000101}
        mySect2 = 3:    BitVector32{00000000000000000000000000011101}
        mySect3 = 1:    BitVector32{00000000000000000000000000111101}
        mySect4 = 9:    BitVector32{00000000000000000000001001111101}
New values:
        mySect1: 5
        mySect2: 3
        mySect3: 1
        mySect4: 9

*/
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
BitVector32 メンバ
System.Collections.Specialized 名前空間
BitArray クラス



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

辞書ショートカット

すべての辞書の索引

「BitVector32 構造体」の関連用語

BitVector32 構造体のお隣キーワード
検索ランキング

   

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



BitVector32 構造体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS