BitVector32 구조체
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
부울 값과 작은 정수는 32비트 메모리에 저장하는 간단한 구조를 제공합니다.
public value class BitVector32
public struct BitVector32
type BitVector32 = struct
Public Structure BitVector32
- 상속
예제
다음 코드 예제에서는 비트 플래그의 컬렉션으로 사용 합니다 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 );
// 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}
다음 코드 예제에서는 섹션의 컬렉션으로 사용 합니다 BitVector32 .
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
설명
BitVector32 는 내부적으로 사용되는 부울 값과 작은 정수보다 BitArray 더 효율적입니다. A BitArray 는 필요에 따라 무기한 증가할 수 있지만 클래스 인스턴스에 필요한 메모리 및 성능 오버헤드가 있습니다. 반면, BitVector32 32비트만 사용합니다.
BitVector32 작은 정수에 대한 섹션 또는 부울의 비트 플래그를 포함하도록 구조체를 설정할 수 있지만 둘 다 포함할 수는 없습니다. A BitVector32.Section 는 창의 창 BitVector32 이며 지정된 최대값을 포함할 수 있는 가장 적은 수의 연속 비트로 구성됩니다 CreateSection. 예를 들어 최대값이 1인 섹션은 1비트만 구성되는 반면 최대값이 5인 섹션은 3비트로 구성됩니다. 최대값이 1인 값을 만들어 BitVector32.Section 부울로 사용할 수 있으므로 정수와 부울을 같은 BitVector32위치에 저장할 수 있습니다.
일부 멤버는 섹션으로 설정된 멤버에 BitVector32 사용할 수 있고 다른 멤버는 비트 플래그로 설정된 멤버에 사용할 수 있습니다. 예를 들어 BitVector32.Item[] 속성은 섹션으로 설정된 인덱서 BitVector32 이고 BitVector32.Item[] 속성은 비트 플래그로 설정된 인덱서 BitVector32 입니다. CreateMask 는 비트 플래그로 설정된 개별 비트에 액세스하는 데 사용할 수 있는 일련의 마스크를 BitVector32 만듭니다.
섹션으로 설정된 마스크를 BitVector32 사용하면 예기치 않은 결과가 발생할 수 있습니다.
생성자
| Name | Description |
|---|---|
| BitVector32(BitVector32) |
기존 구조체에 표시된 데이터를 포함하는 구조체의 BitVector32 새 인스턴스를 초기화합니다 BitVector32 . |
| BitVector32(Int32) |
정수에 표시된 데이터를 포함하는 구조체의 BitVector32 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Data |
정수로 값을 BitVector32 가져옵니다. |
| Item[BitVector32+Section] |
지정된 BitVector32.Section값에 저장된 값을 가져오거나 설정합니다. |
| Item[Int32] |
지정된 마스크로 표시된 비트 플래그의 상태를 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| CreateMask() |
비트 플래그로 설정된 개별 비트를 검색하는 데 사용할 수 있는 일련의 마스크에 첫 번째 마스크를 BitVector32 만듭니다. |
| CreateMask(Int32) |
비트 플래그로 설정된 개별 비트를 검색하는 데 사용할 수 있는 일련의 마스크에서 지정된 마스크 다음에 추가 마스크를 BitVector32 만듭니다. |
| CreateSection(Int16, BitVector32+Section) |
BitVector32.Section 작은 정수가 포함된 일련의 섹션에 지정된 BitVector32.Section 다음 새 항목을 만듭니다. |
| CreateSection(Int16) |
작은 정수가 포함된 일련의 섹션에서 첫 번째 BitVector32.Section 섹션을 만듭니다. |
| Equals(Object) |
지정한 개체 BitVector32가 .에 해당하는지 여부를 확인합니다. |
| GetHashCode() |
에 대한 BitVector32해시 함수로 사용됩니다. |
| ToString() |
현재 BitVector32를 나타내는 문자열을 반환합니다. |
| ToString(BitVector32) |
지정된 BitVector32을 나타내는 문자열을 반환합니다. |