Logical operations

The following functions perform just an ordinary logical operations you may need in your scripts.

Num = And(Num1, Num2)
Num = Or(Num1, Num2)
Num = Xor(Num1, Num2)

BitSet, MaskedValue = TestBit(Value, BitMask)

Num = And(Num1, Num2)
Num = Or(Num1, Num2)
Num = Xor(Num1, Num2)

Nothing special here. Just the usual bitwise AND, OR and XOR operations. All these functions expect two numbers, perform the corresponding operation and return the resulting number. In case you don't remember it right now: you don't have to worry about the missing bitwise NOT operation because Xor(Number, 0xffffffff) will do the trick.

BitSet, MaskedValue = TestBit(Value, BitMask)

This is a slightly more complex beast. This function takes two numbers - one is the value you want to test and the other is just a bit mask - and returns two numbers. The first one is a boolean value which tells if all bits of the mask are set in the input value. The second value returned by the function is the input value without all the bits containing in the mask. Well, sounds terrible but in fact is very simple. Here is the C equivalent of the function:

bool BitSet = (Value & BitMask) == BitMask;
DWORD MaskedValue = Value & ~BitMask;