BitVector32 BitVector32 BitVector32 BitVector32 Struct

Definição

Fornece uma estrutura simples que armazena valores booleanos e inteiros pequenos em 32 bits de memória.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
Herança
BitVector32BitVector32BitVector32BitVector32

Exemplos

O exemplo de código a seguir BitVector32 usa um como uma coleção de sinalizadores de bit.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
End Class


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

O exemplo de código a seguir BitVector32 usa um como uma coleção de seções.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

End Class


' 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

Comentários

BitVector32é mais eficiente do BitArray que para valores Boolianos e pequenos inteiros que são usados internamente.BitVector32 is more efficient than BitArray for Boolean values and small integers that are used internally. Um BitArray pode crescer indefinidamente conforme necessário, mas tem a sobrecarga de memória e desempenho que uma instância de classe requer.A BitArray can grow indefinitely as needed, but it has the memory and performance overhead that a class instance requires. Por outro lado, BitVector32 um usa apenas 32 bits.In contrast, a BitVector32 uses only 32 bits.

Uma BitVector32 estrutura pode ser configurada para conter as seções para pequenos inteiros ou sinalizadores de bits para boolianos, mas não ambos.A BitVector32 structure can be set up to contain either sections for small integers or bit flags for Booleans, but not both. Um BitVector32.Section é uma janela BitVector32 no e é composto pelo menor número de bits consecutivos que podem conter o valor máximo especificado em 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 exemplo, uma seção com um valor máximo de 1 é composta de apenas um bit, enquanto uma seção com um valor máximo de 5 é composta de três 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. Você pode criar um BitVector32.Section com um valor máximo de 1 para servir como um booliano, permitindo assim que você armazene inteiros e boolianos no mesmo 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.

Alguns membros podem ser usados para um BitVector32 que é configurado como seções, enquanto outros membros podem ser usados para um que é configurado como sinalizadores 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 exemplo, a BitVector32.Item[Int32] propriedade é o indexador para um BitVector32 que é configurado como seções e a BitVector32.Item[Int32] propriedade é o indexador para um BitVector32 que é configurado como sinalizadores 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. CreateMaskCria uma série de máscaras que podem ser usadas para acessar bits individuais em um BitVector32 que é configurado como sinalizadores 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.

Usar uma máscara em uma BitVector32 que é configurada como seções pode causar resultados inesperados.Using a mask on a BitVector32 that is set up as sections might cause unexpected results.

Construtores

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

Inicializa uma nova instância da estrutura BitVector32 que contém os dados representados em uma estrutura 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 uma nova instância da estrutura BitVector32 que contém os dados representados em um inteiro.Initializes a new instance of the BitVector32 structure containing the data represented in an integer.

Propriedades

Data Data Data Data

Obtém o valor de BitVector32 como um inteiro.Gets the value of the BitVector32 as an integer.

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

Obtém ou define o valor armazenado no BitVector32.Section especificado.Gets or sets the value stored in the specified BitVector32.Section.

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

Obtém ou define o estado do sinalizador de bit indicado pela máscara especificada.Gets or sets the state of the bit flag indicated by the specified mask.

Métodos

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

Cria a primeira máscara em uma série de máscaras que podem ser usadas para recuperar bits individuais em um BitVector32 configurado como sinalizador de bit.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)

Cria uma máscara adicional após a máscara especificada em uma série de máscaras que podem ser usadas para recuperar bits individuais em um BitVector32 que está configurado como sinalizadores de bit.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)

Cria o primeiro BitVector32.Section em uma série de seções que contêm inteiros pequenos.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)

Cria um novo BitVector32.Section seguindo o BitVector32.Section especificado em uma série de seções que contêm inteiros pequenos.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 se o objeto especificado é igual ao BitVector32.Determines whether the specified object is equal to the BitVector32.

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

Serve como uma função de hash para o BitVector32.Serves as a hash function for the BitVector32.

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

Retorna uma cadeia de caracteres que representa o BitVector32 atual.Returns a string that represents the current BitVector32.

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

Retorna uma cadeia de caracteres que representa o BitVector32 especificado.Returns a string that represents the specified BitVector32.

Aplica-se a

Veja também