BitVector32 BitVector32 BitVector32 BitVector32 Struct

Definición

Proporciona una estructura simple que almacena valores booleanos y pequeños enteros en 32 bits de memoria.Provides a simple structure that stores Boolean values and small integers in 32 bits of memory.

public value class BitVector32
public struct BitVector32
type BitVector32 = struct
Public Structure BitVector32
Herencia
BitVector32BitVector32BitVector32BitVector32

Ejemplos

BitVector32 En el ejemplo de código siguiente se utiliza como una colección de marcadores de bits.The following code example uses a BitVector32 as a collection of bit flags.

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


*/
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}


*/
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}

BitVector32 En el ejemplo de código siguiente se utiliza como una colección de secciones.The following code example uses a BitVector32 as a collection of sections.

#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

*/
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

*/
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

Comentarios

BitVector32es más eficaz que BitArray para los valores booleanos y pequeños enteros que se usan internamente.BitVector32 is more efficient than BitArray for Boolean values and small integers that are used internally. Un BitArray puede crecer indefinidamente según sea necesario, pero tiene la memoria y la sobrecarga de rendimiento que requiere una instancia de clase.A BitArray can grow indefinitely as needed, but it has the memory and performance overhead that a class instance requires. Por el contrario, BitVector32 un solo usa 32 bits.In contrast, a BitVector32 uses only 32 bits.

Se BitVector32 puede configurar una estructura para que contenga cualquiera de las secciones de pequeños enteros o marcas de bits para los valores booleanos, pero no ambos.A BitVector32 structure can be set up to contain either sections for small integers or bit flags for Booleans, but not both. Un BitVector32.Section es una ventana BitVector32 de y se compone del número más pequeño de bits consecutivos que puede contener el valor máximo especificado en CreateSection.A BitVector32.Section is a window into the BitVector32 and is composed of the smallest number of consecutive bits that can contain the maximum value specified in CreateSection. Por ejemplo, una sección con un valor máximo de 1 se compone de un solo bit, mientras que una sección con un valor máximo de 5 se compone de tres bits.For example, a section with a maximum value of 1 is composed of only one bit, whereas a section with a maximum value of 5 is composed of three bits. Puede crear un BitVector32.Section con un valor máximo de 1 para servir como booleano, lo que permite almacenar enteros y valores booleanos en el mismo BitVector32.You can create a BitVector32.Section with a maximum value of 1 to serve as a Boolean, thereby allowing you to store integers and Booleans in the same BitVector32.

Algunos miembros se pueden usar para un BitVector32 que se configura como secciones, mientras que otros miembros se pueden usar para uno que esté configurado como marcas de bits.Some members can be used for a BitVector32 that is set up as sections, while other members can be used for one that is set up as bit flags. Por ejemplo, la BitVector32.Item[Int32] propiedad es el indizador de un BitVector32 que se configura como secciones y la BitVector32.Item[Int32] propiedad es el indizador de un BitVector32 que se configura como marcas de bits.For example, the BitVector32.Item[Int32] property is the indexer for a BitVector32 that is set up as sections, and the BitVector32.Item[Int32] property is the indexer for a BitVector32 that is set up as bit flags. CreateMaskcrea una serie de máscaras que se pueden utilizar para tener acceso a los bits BitVector32 individuales de un que está configurado como marcas de bits.CreateMask creates a series of masks that can be used to access individual bits in a BitVector32 that is set up as bit flags.

El uso de una máscara BitVector32 en un que se configura como secciones podría producir resultados inesperados.Using a mask on a BitVector32 that is set up as sections might cause unexpected results.

Constructores

BitVector32(BitVector32) BitVector32(BitVector32) BitVector32(BitVector32) BitVector32(BitVector32)

Inicializa una nueva instancia de la estructura BitVector32 que contiene los datos representados en una estructura BitVector32 existente.Initializes a new instance of the BitVector32 structure containing the data represented in an existing BitVector32 structure.

BitVector32(Int32) BitVector32(Int32) BitVector32(Int32) BitVector32(Int32)

Inicializa una nueva instancia de la estructura BitVector32 que contiene los datos representados en un entero.Initializes a new instance of the BitVector32 structure containing the data represented in an integer.

Propiedades

Data Data Data Data

Obtiene el valor de BitVector32 como un entero.Gets the value of the BitVector32 as an integer.

Item[BitVector32+Section] Item[BitVector32+Section] Item[BitVector32+Section] Item[BitVector32+Section]

Obtiene o establece el valor almacenado en la BitVector32.Section especificada.Gets or sets the value stored in the specified BitVector32.Section.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Obtiene o establece el estado del marcador de bits que indica la máscara especificada.Gets or sets the state of the bit flag indicated by the specified mask.

Métodos

CreateMask() CreateMask() CreateMask() CreateMask()

Crea la primera máscara de una serie, que puede usarse para recuperar bits individuales en BitVector32 que está configurado en marcadores de bits.Creates the first mask in a series of masks that can be used to retrieve individual bits in a BitVector32 that is set up as bit flags.

CreateMask(Int32) CreateMask(Int32) CreateMask(Int32) CreateMask(Int32)

Crea una máscara adicional que sigue a la máscara especificada de una serie, que puede usarse para recuperar bits individuales en BitVector32 que está configurado en marcadores de bits.Creates an additional mask following the specified mask in a series of masks that can be used to retrieve individual bits in a BitVector32 that is set up as bit flags.

CreateSection(Int16) CreateSection(Int16) CreateSection(Int16) CreateSection(Int16)

Crea la primera BitVector32.Section de una serie de secciones que contienen pequeños enteros.Creates the first BitVector32.Section in a series of sections that contain small integers.

CreateSection(Int16, BitVector32+Section) CreateSection(Int16, BitVector32+Section) CreateSection(Int16, BitVector32+Section) CreateSection(Int16, BitVector32+Section)

Crea una nueva BitVector32.Section que sigue a la BitVector32.Section especificada, de una serie de secciones que contienen pequeños enteros.Creates a new BitVector32.Section following the specified BitVector32.Section in a series of sections that contain small integers.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual a BitVector32.Determines whether the specified object is equal to the BitVector32.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como función hash para BitVector32.Serves as a hash function for the BitVector32.

ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto BitVector32 actual.Returns a string that represents the current BitVector32.

ToString(BitVector32) ToString(BitVector32) ToString(BitVector32) ToString(BitVector32)

Devuelve una cadena que representa la estructura BitVector32 especificada.Returns a string that represents the specified BitVector32.

Se aplica a

Consulte también: