BitVector32.CreateMask Metodo

Definizione

Crea una serie di maschere che possono essere utilizzate per recuperare i singoli bit di una struttura BitVector32 configurata come flag di bit.

Overload

CreateMask()

Crea la prima di una serie di maschere che possono essere utilizzate per recuperare i singoli bit di una struttura BitVector32 configurata come flag di bit.

CreateMask(Int32)

Crea una maschera aggiuntiva, successiva alla maschera specificata all'interno di una serie, che è possibile utilizzare per recuperare i singoli bit di una struttura BitVector32 impostata come flag di bit.

Esempio

Nell'esempio di codice seguente viene illustrato come creare e usare maschere.

#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()

Crea la prima di una serie di maschere che possono essere utilizzate per recuperare i singoli bit di una struttura BitVector32 configurata come flag di bit.

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

Restituisce

Int32

Maschera che consente di isolare il primo flag di bit della struttura BitVector32.

Commenti

Usare CreateMask() per creare la prima maschera in una serie e CreateMask(int) per tutte le maschere successive.

È possibile creare più maschere per fare riferimento allo stesso flag di bit.

La maschera risultante isola un solo flag di bit in BitVector32. È possibile combinare le maschere usando l'operazione OR bit per bit per creare una maschera che isola più flag di bit in BitVector32.

L'uso di una maschera su un BitVector32 oggetto configurato come sezioni potrebbe causare risultati imprevisti.

Questo metodo è un'operazione O(1).

Si applica a

CreateMask(Int32)

Crea una maschera aggiuntiva, successiva alla maschera specificata all'interno di una serie, che è possibile utilizzare per recuperare i singoli bit di una struttura BitVector32 impostata come flag di bit.

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

Parametri

previous
Int32

Maschera che indica il flag di bit precedente.

Restituisce

Int32

Maschera che consente di isolare il flag di bit successivo a quello cui punta previous nella struttura BitVector32.

Eccezioni

previous indica l'ultimo flag di bit nella struttura BitVector32.

Commenti

Usare CreateMask() per creare la prima maschera in una serie e CreateMask(int) per tutte le maschere successive.

È possibile creare più maschere per fare riferimento allo stesso flag di bit.

La maschera risultante isola un solo flag di bit in BitVector32. È possibile combinare le maschere usando l'operazione OR bit per bit per creare una maschera che isola più flag di bit in BitVector32.

L'uso di una maschera su un BitVector32 oggetto configurato come sezioni potrebbe causare risultati imprevisti.

Questo metodo è un'operazione O(1).

Si applica a