>> << & ~ |+ |^ (Bit Operators)

Purpose:

Bit left shift, bit right shift, bit and, bit complement, bit or, bit xor operators.

Syntax:

val1 op val2

val1

-

A scalar, series, or table.

val2

-

A scalar, series, or table.

Returns:

A scalar, series, or table.

Example:

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.

Example:

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.

Example:

W1: {1, 2, 3, 4}

W2: W1 & 0x01

 

returns the series {1, 0, 1, 0} indicating the values that have the lowest bit set.

Example:

W1: {1, 2, 3, 4}

W2: ~W1

 

returns the series {-2, -3, -4, -5}, the bit complement of W1.

Example:

W1: {1, 2, 3, 4}

W2: bitor(W1, 0x01)

 

returns the series {1, 3, 3, 5} by effectively adding 1 to each even value.

Example:

W1: {1, 2, 3, 4}

W2: W1 |+ 0x01

 

returns the series {1, 3, 3, 5}.

Example:

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.

Example:

W1: {1, 2, 3, 4}

W2: W1 |^ 0x01

 

returns the series {0, 3, 2, 5}.

Remarks:

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.

See Also:

Assignment Operators

Conditional Operators

Logical Operators