BitFlags32

Object that wraps an unsigned 32bit flag and provides common bit manipulation functionality.  All operations are Right Handed.

Summary
BitFlags32Object that wraps an unsigned 32bit flag and provides common bit manipulation functionality.
Functions
(1)BitFlags32Takes a Raw storage type (Lua Number)
(2)BitFlags32Takes a BitFlags32 and copies Stored flags to this object
operator==Compare two BitFlags32 for equality.
operator~=Compare two BitFlags32 for inequality.
NKClearClears the BitFlag by setting the Stored number to 0
NKInvertInverts the Sotred number.
NKSetBitSets the Nth bit by setting it to 1.
NKClearBitClears the Nth bit by setting it to 0.
NKFlipBitFlips the state of the Nth bit.
NKCheckBitChecks if the Nth bit is set.
NKShiftRightShifts flags Nth times to the right.
NKShiftLeftShifts flags Nth times to the left.
NKAndAND the given BitFlag with this object and returns a new BitFlag as the result (does not modify this object)
NKOrOR the given BitFlag with this object and returns a new BitFlag as the result (does not modify this object)
NKXorXOR the given BitFlag with this object and returns a new BitFlag the result (does not modify this object)
NKAndWithAND the given BitFlag and stores result in this object (will modify this object’s value)
NKOrWithOR the given BitFlag and stores result in this object (will modify this object’s value)
NKXorWithXOR the given BitFlag and stores result in this object (will modify this object’s value)
NKAnySetCheck to see if the given BitFlags shares any set fields with this object.
NKAllSetCheck to see if the given BitFlags has all set fields matched in this object.
NKNoneSetCheck to see if the given BitFlags has any matching set fields with this object.
NKGetStorageAccess to the raw stored value (useful for saving / sending via network)
NKSetStorageDirectly sets the raw storage value of this object.
NKGetNumBitsReturns number of available bits.

Functions

(1)BitFlags32

Takes a Raw storage type (Lua Number)

(2)BitFlags32

Takes a BitFlags32 and copies Stored flags to this object

operator==

Compare two BitFlags32 for equality.

Parameters

BitFlags32Right hand side BitFlags32.

Returns

booltrue if equal, false if not equal.

operator~=

Compare two BitFlags32 for inequality.

Parameters

BitFlags32Right hand side BitFlags32.

Returns

booltrue if not equal, false if equal.

NKClear

Clears the BitFlag by setting the Stored number to 0

Example

flags = 0

NKInvert

Inverts the Sotred number.

Example

flags = ~flags

NKSetBit

Sets the Nth bit by setting it to 1.

Parameters

NumberNth bit

Example

flags = flags | (1 << n)

NKClearBit

Clears the Nth bit by setting it to 0.

Parameters

NumberNth bit

Example

flags = flags & ~(1 << n)

NKFlipBit

Flips the state of the Nth bit.

Parameters

NumberNth bit

flags = flags ^ (1 << n)

NKCheckBit

Checks if the Nth bit is set.

Parameters

NumberNth bit

Example

bool isSet = flags & (1 << n);

NKShiftRight

Shifts flags Nth times to the right.

Parameters

NumberNumber of shifts

Example

flags = flags << n

NKShiftLeft

Shifts flags Nth times to the left.

Parameters

NumberNumber of shifts

Example

flags = flags >> n

NKAnd

AND the given BitFlag with this object and returns a new BitFlag as the result (does not modify this object)

Parameters

<BitFlags32>Bit Flag to AND with.

Returns

<BitFlags32>Result of AND operation.

Example

unsigned int flagsB = flagsA & flagsB

NKOr

OR the given BitFlag with this object and returns a new BitFlag as the result (does not modify this object)

Parameters

<BitFlags32>Bit Flag to OR with.

Returns

<BitFlags32>Result of OR operation.

Example

unsigned int flagsB = flagsA | flagsB

NKXor

XOR the given BitFlag with this object and returns a new BitFlag the result (does not modify this object)

Parameters

<BitFlags32>Bit Flag to XOR with.

Returns

<BitFlags32>Result of XOR operation.

Example

unsigned int flagsB = flagsA ^ flagsB

NKAndWith

AND the given BitFlag and stores result in this object (will modify this object’s value)

Parameters

<BitFlags32>Bit Flag to AND with.

Example

flagsA = flagsA & flagsB

NKOrWith

OR the given BitFlag and stores result in this object (will modify this object’s value)

Parameters

<BitFlags32>Bit Flag to OR with.

Example

flagsA = flagsA | flagsB

NKXorWith

XOR the given BitFlag and stores result in this object (will modify this object’s value)

Parameters

<BitFlags32>Bit Flag to XOR with.

Example

flagsA = flagsA ^ flagsB

NKAnySet

Check to see if the given BitFlags shares any set fields with this object.

Parameters

<BitFlags32>Bit Flag to check against.

Returns

BooleanOperation result

Example

bool anySet = flagsA & flagsB

NKAllSet

Check to see if the given BitFlags has all set fields matched in this object.

Parameters

<BitFlags32>Bit Flag to check against.

Returns

BooleanOperation result

Example

bool allSet = (flagsA & flagsB) == flagsB

NKNoneSet

Check to see if the given BitFlags has any matching set fields with this object.

Parameters

<BitFlags32>Bit Flag to check against.

Returns

BooleanOperation result

Example

bool noneSet = (flagsA & flagsB) == 0

NKGetStorage

Access to the raw stored value (useful for saving / sending via network)

Returns

NumberRaw storage

Example

local flags = BitFlags32()

flags:NKSetBit(4) -- 0x00000000000000000000000000010000

flags:NKSetBit(6) -- 0x00000000000000000000000001010000

local raw = flags:NKGetStorage()

NKPrint(tostring(raw)) -- Prints: 80

NKSetStorage

Directly sets the raw storage value of this object.  (Similar to Constructors that take BitFlags or Number)

Parameters

NumberRaw storage value

Example

local flagsA = BitFlags32() flagsA:NKSetBit(4) flagsA:NKSetBit(6) flagsA:NKSetBit(8)

local flagsB = BitFlags32() flagsB:NKSetStorage(flagsB:NKGetStorage())

if flagsA:NKAllSet(flagsB) then -- Will evaluate true. end

NKGetNumBits

Returns number of available bits.  Will always return 32 for BitFlags32.

Returns

Numbertotal number of storage bits.

Example

int numBits = sizeof(STORAGE_TYPE) * 8

Object that wraps an unsigned 32bit flag and provides common bit manipulation functionality.
Close