Table of Contents

Class Bitmask

Namespace
ArcanaDevelopment.adTempus.Shared
Assembly
ArcanaDevelopment.adTempus.Shared.dll

Helper functions for working with bitmasks

public static class Bitmask
Inheritance
object
Bitmask

Methods

CreateBitmask(params int[])

Gets a bitmask with a specified bit set. BitMask returns a value in which only the specified bits are set (i.e., is 1).

List of bits to set. Each value must be in the range 0-31. BitMask(0)=1 (binary 00000001) BitMask(1)=2 (binary 00000010) BitMask(2)=4 (binary 00000100)
public static int CreateBitmask(params int[] bits)

Parameters

NameTypeDescription
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

NameTypeDescription
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

NameTypeDescription
value int

The value to check

mask int

The mask containing the bits to check for

Returns

bool

true if value has all bits from mask

Remarks

This tests for a value, not a bit, by performing a bitwise AND between val and mask.

Exceptions

ArgumentOutOfRangeException

Thrown if mask is 0.

SetBit(int, int, bool)

Sets a bit in a bitmask.

public static int SetBit(int val, int bit, bool setting)

Parameters

NameTypeDescription
val int

The bitmask value to update.

bit int

The bit (0 - 31) to set

setting bool

true to set the bit or false to clear it

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

NameTypeDescription
value int

The value to set bits in

mask int

The mask containing the bits to set or clear

setting bool

Specify true to set the bits or false to clear them

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.