BitVector32.CreateMask 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一系列掩码,可用于检索设置为位标志的 BitVector32 单个位。
重载
| 名称 | 说明 |
|---|---|
| CreateMask() |
在一系列掩码中创建第一个掩码,该掩码可用于检索设置为位标志的 BitVector32 单个位。 |
| CreateMask(Int32) |
在一系列掩码中创建一个附加掩码,该掩码可用于检索设置为位标志的单个 BitVector32 位。 |
示例
下面的代码示例演示如何创建和使用掩码。
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}
*/
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)
Console.WriteLine("Initial: " + ControlChars.Tab + "{0}", myBV.ToString())
' Sets the third bit to TRUE.
myBV(myBit3) = True
Console.WriteLine("myBit3 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())
' Combines two masks to access multiple bits at a time.
myBV((myBit4 + myBit5)) = True
Console.WriteLine("myBit4 + myBit5 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())
myBV((myBit1 Or myBit2)) = True
Console.WriteLine("myBit1 | myBit2 = TRUE " + ControlChars.Tab + "{0}", myBV.ToString())
End Sub
End Class
' 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
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
在一系列掩码中创建第一个掩码,该掩码可用于检索设置为位标志的 BitVector32 单个位。
public:
static int CreateMask();
public static int CreateMask();
static member CreateMask : unit -> int
Public Shared Function CreateMask () As Integer
返回
隔离第一个位标志的 BitVector32掩码。
注解
用于 CreateMask() 在序列中创建第一个掩码以及 CreateMask(int) 所有后续掩码。
可以创建多个掩码来引用同一位标志。
生成的掩码仅隔离其中 BitVector32一个位标志。 可以使用按位 OR 操作组合掩码来创建一个掩码,用于隔离多个位标志。BitVector32
在设置为节的设备上 BitVector32 使用掩码可能会导致意外结果。
此方法是 O(1) 操作。
适用于
CreateMask(Int32)
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
- Source:
- BitVector32.cs
在一系列掩码中创建一个附加掩码,该掩码可用于检索设置为位标志的单个 BitVector32 位。
public:
static int CreateMask(int previous);
public static int CreateMask(int previous);
static member CreateMask : int -> int
Public Shared Function CreateMask (previous As Integer) As Integer
参数
- previous
- Int32
指示上一位标志的掩码。
返回
一个掩码,用于隔离指向其中的previous位标志之后的BitVector32位标志。
例外
previous 指示 . 中的 BitVector32最后一个位标志。
注解
用于 CreateMask() 在序列中创建第一个掩码以及 CreateMask(int) 所有后续掩码。
可以创建多个掩码来引用同一位标志。
生成的掩码仅隔离其中 BitVector32一个位标志。 可以使用按位 OR 操作组合掩码来创建一个掩码,用于隔离多个位标志。BitVector32
在设置为节的设备上 BitVector32 使用掩码可能会导致意外结果。
此方法是 O(1) 操作。