Class Bitmask
- Namespace
- ArcanaDevelopment.adTempus.Shared
- Assembly
- ArcanaDevelopment.adTempus.Shared.dll
Helper functions for working with bitmasks
public static class Bitmask
- Inheritance
-
objectBitmask
Methods
CreateBitmask(params int[])
Gets a bitmask with a specified bit set.
public static int CreateBitmask(params int[] bits)
Parameters
| Name | Type | Description |
|---|---|---|
bits |
int[] |
Returns
- int
HasBit(int, int)
Tests whether a specified bit is set in a bitmask.
public static bool HasBit(int val, int bit)
Parameters
| Name | Type | Description |
|---|---|---|
val |
int | The value to test. |
bit |
int | The bit (0 - 31) to test. |
Returns
- bool
HasFlags(int, int)
Tests whether the specified value is included in a bitmask.
public static bool HasFlags(int value, int mask)
Parameters
| Name | Type | Description |
|---|---|---|
value |
int | The value to check |
mask |
int | The mask containing the bits to check for |
Returns
- bool
true if
valuehas all bits frommask
Remarks
This tests for a value, not a bit, by performing a bitwise AND between val and mask.
Exceptions
- ArgumentOutOfRangeException
Thrown if
maskis 0.
SetBit(int, int, bool)
Sets a bit in a bitmask.
public static int SetBit(int val, int bit, bool setting)
Parameters
| Name | Type | Description |
|---|---|---|
val |
int | The bitmask value to update. |
bit |
int | The bit (0 - 31) to set |
setting |
bool |
Returns
- int
SetFlags(int, int, bool)
Sets or clears a mask in a bitmask.
public static int SetFlags(int value, int mask, bool setting)
Parameters
| Name | Type | Description |
|---|---|---|
value |
int | The value to set bits in |
mask |
int | The mask containing the bits to set or clear |
setting |
bool |
Returns
- int
The result of setting or clearing the specified bits in
value
Remarks
This sets or clears a value, not a bit, by performing a bitwise OR between val and mask.