Struct BitField32
A 32-bit array of bits.
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
public struct BitField32
Remarks
Stack allocated, so it does not require thread safety checks or disposal.
Constructors
BitField32(uint)
Initializes and returns an instance of BitField32.
Declaration
public BitField32(uint initialValue = 0)
Parameters
Type | Name | Description |
---|---|---|
uint | initialValue | Initial value of the bit field. Default is 0. |
Fields
Value
The 32 bits, stored as a uint.
Declaration
public uint Value
Field Value
Type | Description |
---|---|
uint | The 32 bits, stored as a uint. |
Methods
Clear()
Clears all the bits to 0.
Declaration
public void Clear()
CountBits()
Returns the number of bits that are 1.
Declaration
public int CountBits()
Returns
Type | Description |
---|---|
int | The number of bits that are 1. |
CountLeadingZeros()
Returns the number of leading zeroes.
Declaration
public int CountLeadingZeros()
Returns
Type | Description |
---|---|
int | The number of leading zeros. |
CountTrailingZeros()
Returns the number of trailing zeros.
Declaration
public int CountTrailingZeros()
Returns
Type | Description |
---|---|
int | The number of trailing zeros. |
GetBits(int, int)
Returns one or more contiguous bits from the bit field as the lower bits of a uint.
Declaration
public uint GetBits(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
int | pos | Position in the bit field of the first bit to get (must be 0-31). |
int | numBits | Number of bits to get (must be 1-32). |
Returns
Type | Description |
---|---|
uint | The requested range of bits from the bit field stored in the least-significant bits of a uint. All other bits of the uint will be 0. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |
IsSet(int)
Returns true if the bit at a position is 1.
Declaration
public bool IsSet(int pos)
Parameters
Type | Name | Description |
---|---|---|
int | pos | Position in the bit field (must be 0-31). |
Returns
Type | Description |
---|---|
bool | True if the bit at the position is 1. |
SetBits(int, bool)
Sets a single bit to 1 or 0.
Declaration
public void SetBits(int pos, bool value)
Parameters
Type | Name | Description |
---|---|---|
int | pos | Position in this bit field to set (must be 0-31). |
bool | value | If true, sets the bit to 1. If false, sets the bit to 0. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |
SetBits(int, bool, int)
Sets one or more contiguous bits to 1 or 0.
Declaration
public void SetBits(int pos, bool value, int numBits)
Parameters
Type | Name | Description |
---|---|---|
int | pos | Position in the bit field of the first bit to set (must be 0-31). |
bool | value | If true, sets the bits to 1. If false, sets the bits to 0. |
int | numBits | Number of bits to set (must be 1-32). |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |