Struct BitField32
Fixed size 32-bit array of bits.
Namespace: Unity.Collections
Syntax
public struct BitField32
Constructors
BitField32(UInt32)
Constructor.
Declaration
public BitField32(uint initialValue = 0U)
Parameters
Type | Name | Description |
---|---|---|
UInt32 | initialValue | Initial value of bit field. Default is 0. |
Fields
Value
32-bit data storage.
Declaration
public uint Value
Field Value
Type | Description |
---|---|
UInt32 |
Methods
Clear()
Clear all bits to 0.
Declaration
public void Clear()
CountBits()
Calculate number of set bits.
Declaration
public int CountBits()
Returns
Type | Description |
---|---|
Int32 | Number of set bits. |
CountLeadingZeros()
Calculate number of leading zeros.
Declaration
public int CountLeadingZeros()
Returns
Type | Description |
---|---|
Int32 | Number of leading zeros |
CountTrailingZeros()
Calculate number of trailing zeros.
Declaration
public int CountTrailingZeros()
Returns
Type | Description |
---|---|
Int32 | Number of trailing zeros |
GetBits(Int32, Int32)
Returns all bits in range as uint.
Declaration
public uint GetBits(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Int32 | numBits | Number of bits to get (must be 1-32). |
Returns
Type | Description |
---|---|
UInt32 | Returns requested range of bits. |
IsSet(Int32)
Returns true is bit at position is set.
Declaration
public bool IsSet(int pos)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Returns
Type | Description |
---|---|
Boolean | Returns true if bit is set. |
SetBits(Int32, Boolean)
Set single bit to desired boolean value.
Declaration
public void SetBits(int pos, bool value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Boolean | value | Value of bits to set. |
SetBits(Int32, Boolean, Int32)
Set bits to desired boolean value.
Declaration
public void SetBits(int pos, bool value, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Boolean | value | Value of bits to set. |
Int32 | numBits | Number of bits to set (must be 1-32). |
TestAll(Int32, Int32)
Returns true if all of bits in range are set.
Declaration
public bool TestAll(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Int32 | numBits | Number of bits to test (must be 1-32). |
Returns
Type | Description |
---|---|
Boolean | Returns true if all bits are set. |
TestAny(Int32, Int32)
Returns true if any of bits in range are set.
Declaration
public bool TestAny(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Int32 | numBits | Number of bits to test (must be 1-32). |
Returns
Type | Description |
---|---|
Boolean | Returns true if at least one bit is set. |
TestNone(Int32, Int32)
Returns true if none of bits in range are set.
Declaration
public bool TestNone(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bitfield (must be 0-31). |
Int32 | numBits | Number of bits to test (must be 1-32). |
Returns
Type | Description |
---|---|
Boolean | Returns true if none of bits are set. |