Struct BitField64
A 64-bit array of bits.
Namespace: Unity.Collections
Syntax
public struct BitField64
Remarks
Stack allocated, so it does not require thread safety checks or disposal.
Constructors
BitField64(UInt64)
Initializes and returns an instance of BitField64.
Declaration
public BitField64(ulong initialValue = 0UL)
Parameters
| Type | Name | Description |
|---|---|---|
| UInt64 | initialValue | Initial value of the bit field. Default is 0. |
Fields
Value
The 64 bits, stored as a ulong.
Declaration
public ulong Value
Field Value
| Type | Description |
|---|---|
| UInt64 | The 64 bits, stored as a uint. |
Methods
Clear()
Clears all 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 ulong.
Declaration
public ulong 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-63). |
| Int32 | numBits | Number of bits to get (must be 1-64). |
Returns
| Type | Description |
|---|---|
| UInt64 | The requested range of bits from the bit field stored in the least-significant bits of a ulong. All other bits of the ulong 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-63). |
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-63). |
| 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 = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | pos | Position in the bit field of the first bit to set (must be 0-63). |
| 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-64). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
TestAll(Int32, Int32)
Returns true if all of the bits in a contiguous range are 1.
Declaration
public bool TestAll(int pos, int numBits = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | pos | Position in the bit field (must be 0-63). |
| Int32 | numBits | Number of bits to test (must be 1-64). |
Returns
| Type | Description |
|---|---|
| Boolean | True if all bits in the contiguous range are 1. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
TestAny(Int32, Int32)
Returns true if any of the bits in a contiguous range are 1.
Declaration
public bool TestAny(int pos, int numBits = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | pos | Position in the bit field (must be 0-63). |
| Int32 | numBits | Number of bits to test (must be 1-64). |
Returns
| Type | Description |
|---|---|
| Boolean | True if at least one bit in the contiguous range is 1. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
TestNone(Int32, Int32)
Returns true if none of the bits in a contiguous range are 1.
Declaration
public bool TestNone(int pos, int numBits = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | pos | Position in the bit field (must be 0-63). |
| Int32 | numBits | Number of bits to test (must be 1-64). |
Returns
| Type | Description |
|---|---|
| Boolean | True if none of the bits in the contiguous range are 1. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |