Bitwise Functions

The following table uses two examples of variables {{var1}} and {{var2}} in expressions using the bitwise symbols.

In the following example, the decimal values for these variables are:

{{var1}} = 8

{{var2}} = 10

Symbol

Description

Example

Result

&

And, used to compare between two parameters, constants, or expressions

{{var1}} & {{var2}}

8 & 3 = 0

|

Or , used to compare between two parameters, constants, or expressions

{{var1}} |{{var2}}

8 | 3 = 11

~

Not , used to invert the value of a parameter, constant, or expression

~({{var1}})

~8 = -9

Xor, , used to compare between two parameters, constants, or expressions

{{var1}} ^ {{var2}}

8 ^ 3 = 11

shl(number, shiftBy)

Shift Left where number must be a local variable, a constant, or another expression and shiftBy sets the number of bits to shift left by the specified number of positions

shl({{var1}}, 3)

8 << 3 = 64

shr(number, shiftBy)

Shift Right where number must be a local variable, a constant, or another expression and shiftBy sets the number of bits to shift right by the specified number of positions

shr({{var1}}, 3)

8 >> 3 = 1

bittest(number, bitIndex)

Bit Test where number is a local variable, a constant, or another expression; and bitIndex sets the position of the bit to test. A bit position of 0 indicates the less significant bit.

(5 , 0)

true

setbit(number, bitIndex, bitValue)

Set Bit

 

 

togglebit(number, bitIndex)

Toggle Bit

 

 

0x

Hexadecimal Constant

 

 

0t

Octal Constant

 

 

0b

Binary Constant

 

 

The bittest function in the Expression Editor evaluates only positive numbers from 0 to 2,147,483,648 or in hex from 00000000 to 7FFFFFFF. Negative numbers between -2,147,483,647 and 0 will be converted to the corresponding positive numbers prior to testing. Numbers above the outside ranges will give you unexpected results.