BitVector32.CreateMask Method

Definition

Creates a series of masks that can be used to retrieve individual bits in a BitVector32 that is set up as bit flags.

Overloads

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(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.

Examples

The following code example shows how to create and use masks.

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

*/

CreateMask()

Source:
BitVector32.cs
Source:
BitVector32.cs
Source:
BitVector32.cs

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.

C#
public static int CreateMask();

Returns

A mask that isolates the first bit flag in the BitVector32.

Remarks

Use 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.

This method is an O(1) operation.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

CreateMask(Int32)

Source:
BitVector32.cs
Source:
BitVector32.cs
Source:
BitVector32.cs

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.

C#
public static int CreateMask(int previous);

Parameters

previous
Int32

The mask that indicates the previous bit flag.

Returns

A mask that isolates the bit flag following the one that previous points to in BitVector32.

Exceptions

previous indicates the last bit flag in the BitVector32.

Remarks

Use 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.

This method is an O(1) operation.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0