Expression Main Functions and Operators
The following tables list the most usual functions and operators supported by the Expression Engine. Note that not all functions and operators are available in all expression contexts.
Base math functions
| Function and syntax | Operation |
| Abs(Var) | Absolute value of Var. |
| Ceil(Var) | Smallest integer greater than or equal to Var. |
| Ceiling(Var) | Smallest integer greater than or equal to Var. |
| Exp(Var) | e raised to power of Var. |
| Floor(Var) | Largest integer less than or equal to Var. |
| IEEERemainder(Var1, Var2) | Remainder after dividing Var1 by Var2. |
| If(Condition,Val_True, Val_False) | If Condition is true returns Val_True, else returns Val_False. |
| Log(Var) | Natural logarithm of Var. |
| Log(Var1, Var2) | Logarithm of Var1 using base Var2. |
| Log10(Var) | Logarithm of Var using base 10. |
| Max(Var1, Var2[, Var3,...,VarN]) | The greater of Var1, Var2, Var3...VarN. |
| Min(Var1, Var2[, Var3,...,VarN]) | The lesser of Var1, Var2, Var3...VarN. |
| Power(Var1, Var2) | Var1 raised to the power of Var2. |
| Round(Var1) | Rounds Var1 to the nearest integer. |
| Round(Var1, Var2) | Rounds Var1 to Var2 decimal places. |
| Sign(Var) | The sign of Var. -1 if it is negative +1 if it is positive. |
| Sqrt(Var) | Square root of Var. |
| Truncate(Var) | Integer part of Var. |
Trigonometric functions
| Function and syntax | Operation |
| Acos(Var) | Angle (in degrees) whose cosine is Var. |
| Asin(Var) | Angle (in degrees) whose sine is Var. |
| Atan(Var) | Angle (in degrees) whose tangent is Var. |
| Cos(Var) | Cosine of Var (angle in degrees). |
| Pi() | Return a rounded value of Pi. |
| Sin(Var) | Sine of the angle Var (angle in degrees). |
| Tan(Var) | Tangent of the angle Var (angle in degrees. |
| ToDegrees(Var) | Convert the value Var from radians to degrees. |
| ToRadians(Var) | Convert the value Var from degrees to radians. |
Conversion functions
| Function and syntax | Operation |
| ToBool(Var) | Convert the value Var to an equivalent boolean value. |
| ToDbl(Var) | Convert the value Var to an equivalent double value. |
String handling functions
It is recommended to enclose text values with quotation marks, and it is mandatory for the expression to work as expected if the value contains a special character such as a space, a comma or a quotation mark. For example: StrRemove('ab,cdefgh', 3, 2).
| Function and syntax | Operation |
| NumIndex(Var[, Bool1]) | Return an integer representing the right or left digits of the string depending on the value of Bool1. By default, Bool1 is false and the function returns the right index. |
| StrCompare(Str1, Str2) | Compare 2 strings Str1 and Str2 and returns an integer that indicates their relationship to one another, taking the case into account. Examples: StrCompare('cba', 'abc') = 1, StrCompare('abc', 'abc') = 0, StrCompare('abc', 'cba') = -1 |
| StrCompareNoCase(Str1, Str2) | As StrCompare but ignoring the case. |
| StrContains(Str1, Str2[, Bool]) | Return true if Str2 is a substring of Str1, return false otherwise. If Bool is true, string comparison is case sensitive, if it is false, string comparison is not case sensitive (default true). |
| StrEqual(Str1, Str2) |
Compare 2 strings Str1 and Str2 and returns 0 if the strings are different or 1 if they are the same, taking the case into account. StrCompare('str1', 'str2') = False, StrCompare('str1', 'STR1') = False, StrCompare('str1', 'str1') = True |
| StrEqualNocase(Str1, Str2) | As StrEqual but ignoring the case. |
| StrExtract(Str1, Chr1, Num1) | Return a substring of Str1 from the position Num1 delimited by the characters Chr1. Examples: StrExtract('My.name.is.John', '.',1) = 'name', StrExtract('My.name.is.John', '.',2) = 'is' |
| StrIndex(Str1[, Bool]) | Return a string representing the right or left digits of Str1 depending on the value of Bool. By default, Bool is false and the function returns the right index. |
| StrIndexOf(Str1, Str2) | Return the index of the first occurrence of the string Str2 in Str1. Returns -1 if Str2 is not found. |
| StrLastIndexOf(Str1, Str2) | Return the index of the last occurrence of the string Str2 in Str1. Returns -1 if Str2 is not found. |
| StrLeft(Str1, Num1) | Return the leftmost Num1 characters of the string Str1. |
| StrLen(Str1) | Return the number of characters in Str1. |
| StrPadInt(Str1, Num1[, Chr1]) | As StrPadLeft, but Chr1 is optional, and if omitted, Str1 is left padded with zeroes. |
| StrPadLeft(Str1, Num1, Chr1) | Left align the characters of Str1, padding on the left with the character Chr1 to the specified total length Num1. Example: StrPadLeft('abcdef' , 10 ,'x') = 'xxxxabcdef' |
| StrPadRight(Str1, Num1, Chr1) | Right align the characters of Str1, padding on the right with the character Chr1 to the specified total length Num1. Example: StrPadRight('abcdef' , 10 ,'x') = 'abcdefxxxx' |
| StrRemove(Str1, Num1[, Num2]) | Return Str1 less the characters from the start position Num1 to the end position Num2. Example: StrRemove('abcdefgh', 3, 2) = 'abcfgh' |
| StrReplace(Str1, Str2, Str3) | Return Str1 with all occurrences of Str2 replaced by Str3. |
| StrReverseExtract(Str1, Chr1, Num1) | Return a substring of Str1 from the position Num1 delimited by the characters Chr1, starting from the end of Str1. Examples: StrReverseExtract('My.name.is.John', '.',1) = 'is', StrReverseExtract('My.name.is.John', '.',2) = 'name' |
| StrRight(Str1, Num1) | Return the rightmost Num1 characters of the string Str1. |
| StrSubstring(Str1, Num1) | Return the substring of Str1 starting at the index position Num1. |
| StrSubstring(Str1, Num1, Num2) | Return the substring of Str1 starting at the index position Num1 and has a length of Num2. |
| StrToLower(Str1) | Return all characters of Str1 as lower case. |
| StrToUpper(Str1) | Return all characters of Str1 as upper case. |
| StrTrim(Str1[, Str2]) | Return Str1 with all leading and trailing occurrences of a set of characters specified in Str2 removed. If Str2 is not specified, the function removes leading and trailing spaces. Example: StrTrim(' *abcdefgh* ', ' *a') = 'bcdefgh' |
| StrTrimEnd(Str1, Str2) | Return Str1 with all trailing occurrences of the set of characters specified in Str2 removed. Example: StrTrimEnd('123abc456xyz789', '123456789') = '123abc456xyz' |
| StrStrimStart(Str1, Str2) | Return Str1 with all leading occurrences of a set of characters specified in Str2 removed. |
| ToStr(Value) | Return the character string corresponding to Value. Value can be of any type. For example, if the Value input is of type boolean, ToStr() will return the string 'true' or 'false'. |
Hexadecimal string handling functions
| Function and syntax | Operation |
| Base64StrToHexStr(Var) | Convert the Var base64 string to a hexadecimal string. |
| HexStrToBit(Var, iPos, iOffset) |
Extract the bit (0 or 1) at the position defined by iPos and iOffset in the hexadecimal string Var. iOffset is the offset of the bit within the single hexadecimal character specified by IPos. |
| HexStrToByte(Var, iPos) | Extract the byte at the position iPos in the hexadecimal string Var. |
| HexStrToFloat(Var, iPos) | Extract the float (IEEE single precision value) at the position iPos in the hexadecimal string Var. |
| HexStrToInt16(Var, iPos) | Extract the Int16 (16 bit value) at position iPos in the hexadecimal string Var. |
| HexStrToInt32(Var, iPos[, iSize]) | Extract the Int32 (32 bit value) at position iPos in the hexadecimal string Var. iSize is the number of bytes to extract (optional - default 4) |
| HexStrToNibble(Var, iPos) | Extract the nibble (4 bit value) at position iPos in the hexadecimal string Var. |
| HexStrToUInt16(Var, iPos) | Extract the UInt16 (unsigned 16 bit value) at position iPos in the hexadecimal string Var. |
| HexStrToUInt32(Var, iPos[, iSize]) | Extract the UInt32 (unsigned 32 bit value) at position iPos in the hexadecimal string Var. iSize is the number of bytes to extract (optional - default 4) |
| ArrayByteStrToBase64Str(Str) | Convert an array of bytes, Integers expressed in decimal, passed as a string into a base64 string. The array can be expressed with syntax '[x,y,z]' or 'x,y,z' For example, if the Str input is the byte array '[3,1,17]', ArrayByteStrToBase64Str returns the string 'AwER'. |
Swapping functions
| Function and syntax | Operation |
| ReverseNibbles(Var) | Reverse the position of nibbles within the decimal value Var. Example: ReverseNibbles(12345) = 37635 (12345 = 0x3039 -> 0x9303 = 37635) |
| SwapBytes(Var) | Swap the byte order of the decimal value Var. Example: SwapBytes(12345) = 14640 (12345 = 0x3039 -> 0x3930 = 14640) |
| SwapNibbles(Var) | Swap the nibble order for each byte of the decimal value Var. Example: SwapNibbles(12345) = 915 (12345 = 0x3039 -> 0x0393 = 915) |
| SwapWords(Var) | Swap the word order of the decimal value Var. Example: SwapWords(12345) = 809 041 920 (12345 = 0x3039 -> 0x30390000 = 809 041 920) |
Operators
| Operator and syntax | Operation | Precedence | Notes |
| ( ) | Parentheses | 1 | Used to control the order of execution. Example: (Var1 * Var2) / (Var1 + Var2). |
| Bitwise operators | Bitwise operators, including left and right shift, discard the fractional part of any values. | ||
| ~ Var1 | Bitwise NOT | 2 | |
| BNOT Var1 | Bitwise NOT | 2 | |
| Var1 & Var2 | Bitwise AND | 8 | |
| Var1 BAND Var2 | Bitwise AND | 8 | |
| Var1 | Var2 | Bitwise OR | 10 | |
| Var1 BOR Var2 | Bitwise OR | 10 | |
| Var1 ^ Var2 | Bitwise XOR | 9 | |
| Var1 XOR Var2 | Bitwise XOR | 9 | |
| Var1 << Var2 | Left shift | 5 | |
| Var1 LSHIFT Var2 | Left shift | 5 | |
| Var1 >> Var2 | Right shift | 5 | |
| Var1 RSHIFT Var2 | Right shift | 5 | |
| Arithmetic operators | |||
| -Var1 | Negate | 2 | |
| Var1 * Var2 | Multiplication | 3 | |
| Var1 / Var2 | Division | 3 | |
| Var1 % Var2 | Modulus | 3 | No longer supported - Use MOD instead. |
| Var1 MOD Var2 | Modulus | 3 | |
| Var1 POW Var2 | Power | 3 | |
| Var1 + Var2 | Addition | 4 | |
| Var1 - Var2 | Subtraction | 4 | |
| Comparison operators | Comparison operators return 1 if true, else 0. | ||
| Var1 == Var2 | Equality | 7 | |
| Var1 = Var2 | Equality | 7 | |
| Var1 != Var2 | Inequality | 7 | |
| Var1 < Var2 | Less than | 6 | |
| Var1 <= Var2 | Less than or equal | 6 | |
| Var1 > Var2 | Greater than | 6 | |
| Var1 >= Var2 | Greater than or equal | 6 | |
| Var1 in (value1, value2,...) | Equality against at least one of many values | 7 | Equivalent to multiple ORed equality tests. |
| Logical operators | Logical operators are intended for use with bit variables. If used with register variables only the LSB is taken into account. | ||
| !Var1 | Logical NOT | 2 | |
| NOT Var1 | Logical NOT | 2 | |
| Var1 || Var2 | Logical OR | 12 | |
| Var1 OR Var2 | Logical OR | 12 | |
| Var1 && Var2 | Logical AND | 11 | |
| Var1 AND Var2 | Logical AND | 11 |
Expression Examples
Motor1.Stop & Motor1.Start | Motor1.Fault
(Inlet.Flow1 + Inlet.Flow2)/100 (note the use of brackets)
Tank1.Temperature & 65520 (masks the first 4 bits of the value)
Sqrt(Inlet.Pressure) (takes the square root)