Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

BitVector32 Structure

Provides a simple structure that stores Boolean values and small integers in 32 bits of memory.

Namespace:  System.Collections.Specialized
Assembly:  System (in System.dll)
'Declaration
Public Structure BitVector32

The BitVector32 type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkBitVector32(BitVector32)Initializes a new instance of the BitVector32 structure containing the data represented in an existing BitVector32 structure.
Public methodSupported by the XNA FrameworkBitVector32(Int32)Initializes a new instance of the BitVector32 structure containing the data represented in an integer.
Top
  NameDescription
Public propertySupported by the XNA FrameworkDataGets the value of the BitVector32 as an integer.
Public propertySupported by the XNA FrameworkItem(BitVector32.Section)Gets or sets the value stored in the specified BitVector32.Section.
Public propertySupported by the XNA FrameworkItem(Int32)Gets or sets the state of the bit flag indicated by the specified mask.
Top
  NameDescription
Public methodStatic memberSupported by the XNA FrameworkCreateMaskCreates 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.
Public methodStatic memberSupported by the XNA FrameworkCreateMask(Int32)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.
Public methodStatic memberSupported by the XNA FrameworkCreateSection(Int16)Creates the first BitVector32.Section in a series of sections that contain small integers.
Public methodStatic memberSupported by the XNA FrameworkCreateSection(Int16, BitVector32.Section)Creates a new BitVector32.Section following the specified BitVector32.Section in a series of sections that contain small integers.
Public methodSupported by the XNA FrameworkEqualsDetermines whether the specified object is equal to the BitVector32. (Overrides ValueType.Equals(Object).)
Public methodSupported by the XNA FrameworkGetHashCodeServes as a hash function for the BitVector32. (Overrides ValueType.GetHashCode.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current BitVector32. (Overrides ValueType.ToString.)
Public methodStatic memberSupported by the XNA FrameworkToString(BitVector32)Returns a string that represents the specified BitVector32.
Top

BitVector32 is more efficient than BitArray for Boolean values and small integers that are used internally. A BitArray can grow indefinitely as needed, but it has the memory and performance overhead that a class instance requires. In contrast, a BitVector32 uses only 32 bits.

A BitVector32 structure can be set up to contain either sections for small integers or bit flags for Booleans, but not both. 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. 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. 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.

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. For example, the BitVector32.Item property is the indexer for a BitVector32 that is set up as sections, and the BitVector32.Item property is the indexer for a BitVector32 that is set up as bit flags. CreateMask creates a series of masks that can be used to access individual bits in a BitVector32 that is set up as bit flags.

Using a mask on a BitVector32 that is set up as sections might cause unexpected results.

The following code example uses a BitVector32 as a collection of bit flags.

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}

The following code example uses a BitVector32 as a collection of sections.

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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft. All rights reserved.