Class BitField
A utility class to aid in working with bit fields
Inheritance
Namespace: Atlas
Assembly: Atlas.Runtime.dll
Syntax
public static class BitField
Examples
namespace Atlas.Examples
{
public sealed class Example_BitField
{
public enum Flags
{
A = 1 << 1, // 0001
B = 1 << 2, // 0010
C = 1 << 3, // 0100
}
public static void Example()
{
// create a bit field with the 'A' and 'C' flags set (0101)
Flags field = Flags.A | Flags.C;
// checks if the 'A' bit is enabled
if ( BitField.IsFlagSet( field, Flags.A ) )
{
// clears only the bit representing 'C'
BitField.ClearFlag( field, Flags.C );
}
}
}
}
Methods
| Improve this Doc View SourceClearFlag(Enum, Enum)
Clears a flag in the given field
Declaration
public static int ClearFlag(Enum bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Enum | bitField | Bit field to modify |
System.Enum | flag | The target flag to clear |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
ClearFlag(Int32, Enum)
Clears a flag in the given field
Declaration
public static int ClearFlag(int bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | Bit field to modify |
System.Enum | flag | The target flag to clear |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
ClearFlag(Int32, Int32)
Clears a flag in the given field
Declaration
public static int ClearFlag(int bitField, int flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | Bit field to modify |
System.Int32 | flag | The target flag to clear |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
IsFlagSet(Enum, Enum)
Determines whether or not the flag is set in the given bit field
Declaration
public static bool IsFlagSet(Enum bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Enum | bitField | The bit field to check |
System.Enum | flag | The target flag to look for |
Returns
Type | Description |
---|---|
System.Boolean | True if the flag is set, false if not |
IsFlagSet(Int32, Enum)
Determines whether or not the flag is set in the given bit field
Declaration
public static bool IsFlagSet(int bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | The bit field to check |
System.Enum | flag | The target flag to look for |
Returns
Type | Description |
---|---|
System.Boolean | True if the flag is set, false if not |
IsFlagSet(Int32, Int32)
Determines whether or not the flag is set in the given bit field
Declaration
public static bool IsFlagSet(int bitField, int flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | The bit field to check |
System.Int32 | flag | The target flag to look for |
Returns
Type | Description |
---|---|
System.Boolean | True if the flag is set, false if not |
SetFlag(Enum, Enum)
Sets a flag in the given field
Declaration
public static int SetFlag(Enum bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Enum | bitField | Bit field to modify |
System.Enum | flag | The target flag to set |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
SetFlag(Int32, Enum)
Sets a flag in the given field
Declaration
public static int SetFlag(int bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | Bit field to modify |
System.Enum | flag | The target flag to set |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
SetFlag(Int32, Int32)
Sets a flag in the given field
Declaration
public static int SetFlag(int bitField, int flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | Bit field to modify |
System.Int32 | flag | The target flag to set |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
SetFlag(Int32, Int32, Boolean)
Sets a flag in the given field
Declaration
public static int SetFlag(int bitField, int flag, bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | Bit field to modify |
System.Int32 | flag | The target flag to set |
System.Boolean | value | The value to set the flag to |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
ToggleFlag(Enum, Enum)
Toggles a flag in the given field
Declaration
public static int ToggleFlag(Enum bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Enum | bitField | The bit field to modify |
System.Enum | flag | The target flag to toggle |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
ToggleFlag(Int32, Enum)
Toggles a flag in the given field
Declaration
public static int ToggleFlag(int bitField, Enum flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | The bit field to modify |
System.Enum | flag | The target flag to toggle |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |
ToggleFlag(Int32, Int32)
Toggles a flag in the given field
Declaration
public static int ToggleFlag(int bitField, int flag)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bitField | The bit field to modify |
System.Int32 | flag | The target flag to toggle |
Returns
Type | Description |
---|---|
System.Int32 | The modified bit field |