Bit left shift, bit right shift, bit and, bit complement, bit or, bit xor operators.
val1 op val2
val1 |
- |
A scalar, series, or table. |
val2 |
- |
A scalar, series, or table. |
A scalar, series, or table.
W1: {1, 2, 3, 4}
W2: W1 >> 1
returns the series {0, 1, 1, 2}. The bits of each value in the series are shifted one place to the right resulting in an integer divide by 2.
W1: {1, 2, 3, 4}
W2: W1 << 1
returns the series {2, 4, 6, 8}. The bits of each value in the series are shifted one place to the left resulting in an integer multiply by 2.
W1: {1, 2, 3, 4}
W2: W1 & 0x01
returns the series {1, 0, 1, 0} indicating the values that have the lowest bit set.
W1: {1, 2, 3, 4}
W2: ~W1
returns the series {-2, -3, -4, -5}, the bit complement of W1.
W1: {1, 2, 3, 4}
W2: bitor(W1, 0x01)
returns the series {1, 3, 3, 5} by effectively adding 1 to each even value.
W1: {1, 2, 3, 4}
W2: W1 |+ 0x01
returns the series {1, 3, 3, 5}.
W1: {1, 2, 3, 4}
W2: bitxor(W1, 0x01)
returns the series {0, 3, 2, 5} by effectively adding 1 to each even value and subtracting 1 from each odd value.
W1: {1, 2, 3, 4}
W2: W1 |^ 0x01
returns the series {0, 3, 2, 5}.
The following bit operators are supported:
Operator |
Function |
Description |
>> |
BITRSHIFT |
bit shift right |
<< |
BITLSHIFT |
bit shift left |
& |
BITAND |
bit and |
~ |
BITCOMP |
bit complement |
|+ |
BITOR |
bit or |
|^ |
BITXOR |
bit exclusive or |
The | symbol is not used as the BITOR operator since | is the deprecated pipe operator. Use |+ to implement BITOR.
The ^ symbol is not used as the BITXOR operator since ^ is the exponentiation operator. Use |^ to implement BITXOR.