summaryrefslogtreecommitdiff
path: root/npc/functions/bitwise.txt
blob: 58ad8b5cdbfade2998406a2379a045084dbae43a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
 * gets a bitmasked value in a variable
 *
 * @arg 0 - the variable
 * @arg 1 - mask
 * @arg 2 - shift
 */
function	script	bitwise_get	{
    return (getarg(0) & getarg(1)) >> getarg(2, 0);
}

/**
 * sets a bitmasked value in a variable
 *
 * @arg 0 - the target variable
 * @arg 1 - mask
 * @arg 2 - shift
 * @arg 3 - new value
 * @return a reference to the variable
 */
function	script	bitwise_set	{
    return set(getarg(0), (getarg(0) & ~(getarg(1))) | (getarg(3, 0) << getarg(2, 0)));
}