Struct BitField64
A 64-bit array of bits.
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
public struct BitField64
Remarks
Stack allocated, so it does not require thread safety checks or disposal.
Constructors
BitField64(ulong)
Initializes and returns an instance of BitField64.
Declaration
public BitField64(ulong initialValue = 0)
Parameters
Type | Name | Description |
---|---|---|
ulong | 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 |
---|---|
ulong | 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 |
---|---|
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 ulong.
Declaration
public ulong 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-63). |
int | numBits | Number of bits to get (must be 1-64). |
Returns
Type | Description |
---|---|
ulong | 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(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-63). |
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-63). |
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 = 1)
Parameters
Type | Name | Description |
---|---|---|
int | pos | Position in the bit field of the first bit to set (must be 0-63). |
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-64). |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |