BitVector32.CreateMask 方法

定義

建立一系列遮罩,可以用於擷取設定為位元旗標之 BitVector32 中的個別位元。

多載

CreateMask()

建立一系列遮罩中的第一個遮罩,可以用於擷取設定為位元旗標之 BitVector32 中的個別位元。

CreateMask(Int32)

在一系列遮罩中的指定遮罩之後建立額外的遮罩,可以用於擷取設定為位元旗標之 BitVector32 中的個別位元。

範例

下列程式代碼範例示範如何建立和使用遮罩。

#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;

   // 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 );
   Console::WriteLine( "Initial:               \t {0}", myBV );

   // Sets the third bit to TRUE.
   myBV[ myBit3 ] = true;
   Console::WriteLine( "myBit3 = TRUE          \t {0}", myBV );

   // Combines two masks to access multiple bits at a time.
   myBV[ myBit4 + myBit5 ] = true;
   Console::WriteLine( "myBit4 + myBit5 = TRUE \t {0}", myBV );
   myBV[ myBit1 | myBit2 ] = true;
   Console::WriteLine( "myBit1 | myBit2 = TRUE \t {0}", myBV );
}

/*
This code produces the following output.

Initial:                BitVector32 {00000000000000000000000000000000}
myBit3 = TRUE           BitVector32 {00000000000000000000000000000100}
myBit4 + myBit5 = TRUE  BitVector32 {00000000000000000000000000011100}
myBit1 | myBit2 = TRUE  BitVector32 {00000000000000000000000000011111}

*/
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 );
      Console.WriteLine( "Initial:               \t{0}", myBV.ToString() );

      // Sets the third bit to TRUE.
      myBV[myBit3] = true;
      Console.WriteLine( "myBit3 = TRUE          \t{0}", myBV.ToString() );

      // Combines two masks to access multiple bits at a time.
      myBV[myBit4 + myBit5] = true;
      Console.WriteLine( "myBit4 + myBit5 = TRUE \t{0}", myBV.ToString() );
      myBV[myBit1 | myBit2] = true;
      Console.WriteLine( "myBit1 | myBit2 = TRUE \t{0}", myBV.ToString() );
   }
}

/*
This code produces the following output.

Initial:                BitVector32{00000000000000000000000000000000}
myBit3 = TRUE           BitVector32{00000000000000000000000000000100}
myBit4 + myBit5 = TRUE  BitVector32{00000000000000000000000000011100}
myBit1 | myBit2 = TRUE  BitVector32{00000000000000000000000000011111}

*/
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)
      Console.WriteLine("Initial:               " + ControlChars.Tab + "{0}", myBV.ToString())
      
      ' Sets the third bit to TRUE.
      myBV(myBit3) = True
      Console.WriteLine("myBit3 = TRUE          " + ControlChars.Tab + "{0}", myBV.ToString())
      
      ' Combines two masks to access multiple bits at a time.
      myBV((myBit4 + myBit5)) = True
      Console.WriteLine("myBit4 + myBit5 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())
      myBV((myBit1 Or myBit2)) = True
      Console.WriteLine("myBit1 | myBit2 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())

   End Sub

End Class


' This code produces the following output.
'
' Initial:                BitVector32{00000000000000000000000000000000}
' myBit3 = TRUE           BitVector32{00000000000000000000000000000100}
' myBit4 + myBit5 = TRUE  BitVector32{00000000000000000000000000011100}
' myBit1 | myBit2 = TRUE  BitVector32{00000000000000000000000000011111}

CreateMask()

來源:
BitVector32.cs
來源:
BitVector32.cs
來源:
BitVector32.cs

建立一系列遮罩中的第一個遮罩,可以用於擷取設定為位元旗標之 BitVector32 中的個別位元。

public:
 static int CreateMask();
public static int CreateMask ();
static member CreateMask : unit -> int
Public Shared Function CreateMask () As Integer

傳回

遮罩,隔離 BitVector32 中的第一個位元旗標。

備註

用來 CreateMask() 在數列中建立第一個遮罩,並 CreateMask(int) 用於所有後續遮罩。

您可以建立多個遮罩來參考相同的位旗標。

產生的遮罩只會隔離 中的 BitVector32一個位旗標。 您可以使用位 OR 作業結合遮罩,以建立遮罩,以隔離 中的 BitVector32多個位旗標。

在設定為區段的 上使用 BitVector32 遮罩可能會導致非預期的結果。

這個方法是 O (1) 作業。

適用於

CreateMask(Int32)

來源:
BitVector32.cs
來源:
BitVector32.cs
來源:
BitVector32.cs

在一系列遮罩中的指定遮罩之後建立額外的遮罩,可以用於擷取設定為位元旗標之 BitVector32 中的個別位元。

public:
 static int CreateMask(int previous);
public static int CreateMask (int previous);
static member CreateMask : int -> int
Public Shared Function CreateMask (previous As Integer) As Integer

參數

previous
Int32

遮罩,表示前一個的位元旗標。

傳回

遮罩,隔離 BitVector32previous 所指向之位元旗標之後的位元旗標。

例外狀況

previous,表示 BitVector32 中的最後一個位元旗標。

備註

用來 CreateMask() 在數列中建立第一個遮罩,並 CreateMask(int) 用於所有後續遮罩。

您可以建立多個遮罩來參考相同的位旗標。

產生的遮罩只會隔離 中的 BitVector32一個位旗標。 您可以使用位 OR 作業結合遮罩,以建立遮罩,以隔離 中的 BitVector32多個位旗標。

在設定為區段的 上使用 BitVector32 遮罩可能會導致非預期的結果。

這個方法是 O (1) 作業。

適用於