public struct BitVector32
|
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 BitVector32.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 [Section] property is the indexer for a BitVector32 that is set up as sections, and the BitVector32.Item [int] property is the indexer for a BitVector32 that is set up as bit flags. BitVector32.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.
using System; using System.Collections.Specialized; using System.Windows.Forms; public class Form1: Form { protected TextBox textBox1; // Creates three sections for a bit vector. private static readonly BitVector32.Section first = BitVector32.CreateSection(2); private static readonly BitVector32.Section second = BitVector32.CreateSection(1, first); private static readonly BitVector32.Section third = BitVector32.CreateSection(5, second); // Creates two masks for the bit vector. private static readonly int MaskOne = BitVector32.CreateMask(); private static readonly int MaskTwo = BitVector32.CreateMask(MaskOne); private void MyMethod() { // Creates a new bit vector, using the first and third sections. // The first section has a maximum of two as defined above. BitVector32 b = new BitVector32(); b[first] = 1; // The third section has a maximum of five. b[third] = 3; // Creates another bit vector, with Mask One. BitVector32 anotherB = new BitVector32(); anotherB[MaskOne] = true; } }
ctor #1 | Overloaded:.ctor(BitVector32 value) Initializes a new instance of the BitVector32 structure containing the data represented in an existing BitVector32 structure. |
ctor #2 | Overloaded:.ctor(int data) Initializes a new instance of the BitVector32 structure containing the data represented in an integer. |
Data | Read-only Gets the value of the BitVector32 as an integer. |
Item | Read-write Overloaded: Item[BitVector32.Section section] {get Gets or sets the value stored in the specified BitVector32.Section. |
Item | Read-write Overloaded: Item[int bit] {get Gets or sets the state of the bit flag indicated by the specified mask. |
CreateMask | Overloaded:CreateMask() 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 | Overloaded:CreateMask(int previous) 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 | Overloaded:CreateSection(short maxValue) Creates the first BitVector32.Section in a series of sections that contain small integers. |
CreateSection | Overloaded:CreateSection(short maxValue, BitVector32.Section previous) Creates a new BitVector32.Section following the specified BitVector32.Section in a series of sections that contain small integers. |
Equals | Overridden: Determines whether the specified object is equal to the BitVector32. |
GetHashCode | Overridden: Serves as a hash function for the BitVector32. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString | Overloaded:ToString() Overridden: Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code |
ToString | Overloaded:ToString(BitVector32 value) Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public BitVector32(BitVector32( |
value
public BitVector32( |
data
public int Data {get;}
|
public int this[BitVector32.Section section] {get; set;}
|
section
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 BitVector32.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.
public bool this[int bit] {get; set;}
|
bit
Using this property on a BitVector32 that is set up as sections might cause unexpected results.
public static int CreateMask(); |
CreateMask()
to create the first mask in a series and
CreateMask(int)
for all subsequent masks.Multiple masks can be created to refer to the same bit flag.
The resulting mask isolates only one bit flag in the BitVector32. You can combine masks using the bitwise OR operation to create a mask that isolates multiple bit flags in the BitVector32.
Using a mask on a BitVector32 that is set up as sections might cause unexpected results.
previous
Exception Type | Condition |
---|---|
InvalidOperationException | previous indicates the last bit flag in the BitVector32. |
CreateMask()
to create the first mask in a series and
CreateMask(int)
for all subsequent masks.Multiple masks can be created to refer to the same bit flag.
The resulting mask isolates only one bit flag in the BitVector32. You can combine masks using the bitwise OR operation to create a mask that isolates multiple bit flags in the BitVector32.
Using a mask on a BitVector32 that is set up as sections might cause unexpected results.
maxValue
Exception Type | Condition |
---|---|
ArgumentException | maxValue is less than 1. |
If sections already exist in the BitVector32, those sections are still accessible; however, overlapping sections might cause unexpected results.
public static Section CreateSection( |
maxValue
previous
Exception Type | Condition |
---|---|
ArgumentException | maxValue is less than 1. |
InvalidOperationException | previous includes the final bit in the BitVector32. -or- maxValue is greater than the highest value that can be represented by the number of bits after previous. |
If sections already exist after previous in the BitVector32, those sections are still accessible; however, overlapping sections might cause unexpected results.
o
~BitVector32(); |
public override int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public override string ToString(); |
public static string ToString( |
value