Struct BitField32
A 32-bit array of bits.
Namespace: Unity.Collections
Syntax
public struct BitField32
Remarks
Stack allocated, so it does not require thread safety checks or disposal.
Constructors
BitField32(UInt32)
Initializes and returns an instance of BitField32.
Declaration
public BitField32(uint initialValue = 0U)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | 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 |
---|---|
UInt32 | 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 |
---|---|
Int32 | The number of bits that are 1. |
CountLeadingZeros()
Returns the number of leading zeroes.
Declaration
public int CountLeadingZeros()
Returns
Type | Description |
---|---|
Int32 | The number of leading zeros. |
CountTrailingZeros()
Returns the number of trailing zeros.
Declaration
public int CountTrailingZeros()
Returns
Type | Description |
---|---|
Int32 | The number of trailing zeros. |
GetBits(Int32, Int32)
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 |
---|---|---|
Int32 | pos | Position in the bit field of the first bit to get (must be 0-31). |
Int32 | numBits | Number of bits to get (must be 1-32). |
Returns
Type | Description |
---|---|
UInt32 | 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(Int32)
Returns true if the bit at a position is 1.
Declaration
public bool IsSet(int pos)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in the bit field (must be 0-31). |
Returns
Type | Description |
---|---|
Boolean | True if the bit at the position is 1. |
SetBits(Int32, Boolean)
Sets a single bit to 1 or 0.
Declaration
public void SetBits(int pos, bool value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in this bit field to set (must be 0-31). |
Boolean | value | If true, sets the bit to 1. If false, sets the bit to 0. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |
SetBits(Int32, Boolean, Int32)
Sets one or more contiguous bits to 1 or 0.
Declaration
public void SetBits(int pos, bool value, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in the bit field of the first bit to set (must be 0-31). |
Boolean | value | If true, sets the bits to 1. If false, sets the bits to 0. |
Int32 | numBits | Number of bits to set (must be 1-32). |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |