Expressions support the following bitwise operators and functions:
&, |, # |
Bitwise AND, Bitwise OR, Bitwise XOR |
~ |
Bitwise NOT (8 bit) |
~~ |
Bitwise NOT (16 bit) |
~~~ |
Bitwise NOT (32 bit) |
<<, >> |
Shift Left, Shift Right |
TestBit(x, #) |
Returns 0 or 1 status of bit # of x (0 indexed) |
SetBit(x, #) |
Sets bit # of x to 1 (0 indexed) |
ClearBit(x, #) |
Clears bit # of x to 0 (0 indexed) |
When evaluating bitwise operators and functions, all non-integer values are rounded down. For some advanced bitwise conversion, please see the section on byte conversions.
Examples: given using binary notation:
0b0100110 & 0b0101001 returns 0b0100000
0b0100110 | 0b0101001 returns 0b0101111
~0b0100110 returns 0b11011001 Note how the input value is filled out to 8 bits before performing the NOT.
~~0b0100110 returns 0b11111111 11011001 Note how the input value is filled out to 16 bits before performing the NOT.
0b0100110 << 1 returns 0b1001100
0b0100110 >> 1 returns 0b0010011
TestBit(0b0100110, 2) returns 1
SetBit(0b0100110, 3) returns 0b0101110
ClearBit(0b0100110, 2) returns 0b0100010
The bitwise operators, but not the Test, Set, ClearBit functions, can be applied to arrays:
{0b1010, 0b0111} << 2 returns {0b101000,0b11100}