Chapter 4
Expressions
Combining Variables, Constants, and Operators to Form Expressions
Expressions represent values. They are used in statements (assignments, conditions, loops, and commands) to form a statement that the computer can understand.
To create expressions, you use variables and constants. Variables represent data that can change while a macro is playing. Constants represent data items that cannot change during macro play. Variables and constants are combined with operators (+, -, *, %, etc.) to create expressions.
In the following example, vCount is a variable. The values 0, 4, and -1 are used as constants. Then the - and = operators are used to create expressions: vCount - 1, vCount = 0, and vCount = 4.
FUNCTION BeepBeep(vCount)
REPEAT
BEEP
WAIT(3)
vCount := vCount - 1
UNTIL(vCount = 0)
RETURN
ENDFUNC
FOREACH(vCount; {1; 2; 3; 4; 5})
IF(vCount = 4)
BREAK
ENDIF
BeepBeep(vCount)
WAIT(5)
ENDFOR
MESSAGEBOX(x; "BREAK"; "Variable vCount equals 4"; IconInformation!)
QUIT
This chapter discusses variables, constants, and operators more thoroughly.
Variables
Variables point to a memory cell where data is stored. The variable name represents the data’s address or location. A variable can store only one data item at a time, which can be of any type and can change during macro play. Use the programming commands Declare, Local, Global, or Persist to declare variables.
Adjacent memory cells, associated by a name, are collectively called an array. Use Declare, Local, Global, or Persist programming commands to declare an array name and the number of cells, or elements, associated with it. Assign a value to an array element in the same way you assign a value to a variable. For example,
Declare Test[10]
Test[1] := 5
creates a 10-element array named Test, and assigns 5 to element 1. Array elements can contain different data types, such as numbers or character strings. See PerfectScript Declare command for array examples.
A run-time error occurs if you reference a variable or array element that has not been assigned a value.
Variable and array names are user defined, are not case sensitive, must begin with a letter, can include any combination of letters or numbers, and are limited to 50 characters. The following examples assign a right operand expression to a left operand variable (variable can also be an array element).
Examples
x := "John Doe"
Result: x equals John Doe (character string)
vLeftMargin := 5i
Result: vLeftMargin equals 5i (measurement expression)
ResultOfOperation := 3 + 4
Result: ResultOfOperation equals 7 (numeric expression)
z := z + 1
Result: z equals the value of z + 1 (Because a variable can contain only one value at a time, the original value of z is lost unless previously assigned to another variable.)
x := y > 1
Result: x equals the result of relational expression y > 1 (x equals True if y contains a value greater than 1, or False if y contains a value less than or equal to 1).
The following example evaluates the result of y > 1, without assigning the result to a variable. The computer beeps if the value of y is greater than 1 (if the result of expression y > 1 equals True). Beep is skipped if the value of y is less than or equal to 1 (if the expression result equals False).
If (y > 1)
Beep
Endif
Variable Programming Commands
Constant
Defines a constant variable (an identifier whose value cannot change at run-time). Constants make macros easier to read. See PerfectScript Constant command.
Declare
Declare creates local variables and arrays (they pertain only to the current macro). An array can have up to 10 dimensions, and up to 32,767 elements per dimension depending on the amount of available memory (see PerfectScript Declare and Local commands).
Global
Global creates variables and arrays that pertain to the current macro and to macros called by Run or Chain (see PerfectScript Chain, Global, and Run commands).
Indirect
Indirect creates a variable name out of a combination of character strings and/or numbers. See PerfectScript Indirect command. You can use Indirect wherever you can use a variable.
Indirect can also create a Label name out of a combination of character strings and/or numbers, and can be used in most places where you can use a label. See Subroutines in Chapter 5: Conditional, Loop, and Calling Statements.
Local
Local creates local variables and arrays (they pertain only to the current macro). Variables declared in user-defined functions and procedures are local to those subroutines. When you create a variable by assigning it a value, the variable is automatically declared Local (see PerfectScript Local command).
Persist
Persist creates variables and arrays that pertain to any PerfectScript macro as long as PerfectScript is running (see PerfectScript Persist and PersistAll commands)nq
Special Variables
MacroDialogResult
MacroDialogResult is an implicit variable (one defined by PerfectScript) that contains the Control value of the button that dismisses a dialog box. See Creating a Dialog Box with Macro Commands in Chapter 7: Dialog Boxes and PerfectScript DialogDefine command.
ErrorNumber
ErrorNumber is a system variable that contains the error value of a Cancel, Error, or NotFound condition. See PerfectScript Assert command and the ASSERT.WCM example (line 44) in Chapter 9: Macro Examples.
MacroArgs[]
MacroArgs [] is a special array variable that contains values passed to the macro by Chain, Nest, or Run. For example,
// Macro: MAIN.WCM
// Include full path if macro not
// in default macros directory
Run("TSTMACRO"; {"x"; "y"; "z"})
// Macro: TSTMACRO.WCM
// Compile, then play MAIN.WCM
vElements = Dimensions (MacroArgs[]; 0)
If (vElements != 0)
ForNext (x; 1; vElements; 1)
MessageBox (z; "Element Values"; "MacroArgs[" + x + "] = " + MacroArgs[x])
EndFor
Else
Beep
MessageBox (z; "Error"; "No values passed"; IconExclamation!)
EndIf
// Result: x y z
System Variables
System variables contain current system information such as the current chart type or the default directory. In Corel WordPerfect, system variables begin with a question mark. In Corel Presentations, system variables begin with Env (they return information about the application environment). For example,
vMacroPath := ?PathMacros
assigns the path and name of the default Corel WordPerfect macros directory to a variable named vMacroPath. If you change the directory, the system variable ?PathMacros is updated to reflect the change. The equivalent macro command in Corel Presentations is EnvPaths(Macros!).
Constants
Constants represent data items that cannot change during macro play. For example,
Switch (x)
CaseOf 1: CALL (Start)
CaseOf 2: CALL (Stop)
EndSwitch
contains two CaseOf statements, followed by numeric constants 1 and 2. If variable x equals 1, a subroutine named Start is called. If x equals 2, a subroutine named Stop is called.
Operators
Operators are used to combine variables, constants, and expressions into other expressions. Macros support the following operators:
Operator Precedence
The following table shows operator precedence, which is applied to expressions.
| Precedence Level | Operators |
| 1 | Parentheses (), unary minus (-), unary plus (+), bitwise not (~), logical not (NOT) |
| 2 | ** exponentiation |
| 3 | Multiply (*), divide (/), modulus division (% or MOD), integer division (DIV) |
| 4 | Add (+), subtract (-) |
| 5 | Shift left (<<), shift right (>>), rotate left (<<<), rotate right (>>>) |
| 6 | Equal (=), not equal (<> or !=), less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), membership (IN), string case-insensitive equality (LIKE) |
| 7 | Bitwise and (&), bitwise or (|), bitwise XOR (^) |
| 8 | Logical and (AND) |
| 9 | Logical or (OR), logical xor (XOR) |
| 10 | Assignment (:= or =) |
Operator Rules
Operator Precedence Examples
x := ((50 * 5 + 50) * 3 + 100)
Result: x equals 1000 (50 * 5 = 250, 250 + 50 = 300, 300 * 3 = 900, 900 + 100 = 1000)
x := ((50 * (5 + 50)) * 3 + 100)
Result: x equals 8350 (5 + 50 = 55, 55 * 50 = 2750, 2750 * 3 = 8250, 8250 + 100 = 8350)
x := ((50 * 5 + 50) * (3 + 100))
Result: x equals 30900 (50 * 5 = 250, 250 + 50 = 300, 3 + 100 = 103, 300 * 103 = 30900)
Unary Operators
Unary operators are symbols or words that represent an operation on only one operand or expression.
| Operator | Action |
| + | Multiplies an operand by +1 |
| - | Multiplies an operand by -1 |
| NOT | Inverts the result of relational and logical expressions |
Unary plus/minus (+/-) examples
+5
Result: +5 is the result of 5 * +1
-10
Result: -10 is the result of 10 * -1
NOT example
x := 5
y := (x < 10)
z := NOT(x < 10)
Explanation: True is assigned to y (x is less than 10). False is assigned to z (the inverted result of the expression x < 10).
NOT example in an IF statement
x := 5
z := (x < 10)
If (NOT(z))
Beep
Else
Quit
EndIf
Explanation: The result of the expression x < 10 is assigned to variable z. Beep causes the computer to beep if the inverted value of z equals True. Because the inverted value of z equals False, there is no beep, and the Else statement is played. Quit ends the macro.
NOT example in shorthand notation
x := 5
If (NOT(x < 10))
Beep
Else
Quit
EndIf
Explanation: If instructs the computer to beep if the inverted result of the expression x < 10 equals True. Because the result of NOT(x < 10) equals False, there is no beep and the Else statement is played. Quit ends the macro.
Previous example without NOT operator
x := 5
If (x > 10)
Beep
Else
Quit
EndIf
Explanation: If the result of the expression x > 10 equals True, beep. Because the result equals False (the value of x is less than 10), the Else statement is played. Quit ends the macro.
Binary Operators
Symbols that represent an operation on two operands or expressions. For example,
x := 3 + 4
contains the binary plus operator (+) which adds the operands 3 and 4. The assignment operator (:=) assigns the result of the arithmetic expression 3 + 4 to variable x.
There are four types of binary operators. More complete explanations follow the table.
| Operator Type | Description |
| Arithmetic Operators | Symbols or words that represent a mathematical operation on two operands. |
| Relational Operators | Symbols that represent a relational operation on two operands. The operation result equals True or False. |
| Logical Operators | Words that represent a logical relationship between conditions, or that invert a condition. The condition is the result of a relational expression. |
| Bitwise Operators | Symbols that represent a bitwise operation on two integer operands. |
Arithmetic Operators
Arithmetic operators are symbols or words that represent a mathematical operation on two operands.
| Operator | Action |
| * | Multiplication |
| / | Division |
| - | Subtraction of numbers and reduction of strings |
| + | Addition of numbers and concatenation of strings |
| % | Floating point modulus division returns floating point division remainder |
| MOD | Integer modulus division returns integer division remainder |
| DIV | Integer division returns integer portion of integer division |
| ** | Exponentiation or raising a number to a power |
+ (string) example
vStr := "abcdefg" + "xyz "
Result: vStr = "abcdefgxyz"
- (string) example
vStr := "abcdefg xyz" - " xyz"
Result: vStr = "abcdefg"
** examples
vResult = 2**3
Result: vResult = 8 (2 to the 3rd power)
vResult = 4**2
Result: vResult = 16 (4 to the 2nd power)
% examples
x:=10.1 % 3
Result: x equals 1.1
x := 9 % 3
Result: x equals 0
MOD examples
x := 10 MOD 3
Result: x equals 1
x := 10.1 MOD 3
Result: error (cannot use MOD on real numbers)
DIV examples
x := 10 DIV 3
Result: x equals 3
x := 9 DIV 3
Result: x = 3
x := 9.1 DIV 3.5
Result: error (cannot use DIV on real numbers)
Relational Operators
Relational operators are symbols that represent a relational operation on two operands. The operation result equals True or False.
| Operator | Action |
| > | Greater than |
| >= | Greater than or equal to |
| < | Less than |
| <= | Less than or equal to |
| = | Equal to |
| <> | Not equal to |
| != | Not equal to |
| IN | Membership |
| LIKE | Case-insensitive string equality. Unlike =, which is True only if the two strings being compared are identical including uppercase and lowercase, LIKE disregards uppercase and lowercase, treating them the same. |
Greater than (>) example
x := 10
z := (x > 5)
Result: z equals True (x is greater than 5).
Less than (<) example
z := (x < 5)
Result: z equals False (x is not less than 5).
Equal to (=) examples
x := 10
z := (x=5)
Result: z equals False (x is not equal to 5).
x := 10
z := (x = 10)
Result: z equals True (x is equal to 10)
x := "Abc"
z := (x = "Abc")
Result: z equals True ( x is equal to "Abc").
x := "Abc"
z := "abc"
Result: z equals False (x must be the same as "Abc," including case).
Not equal (<> or !=) example
x := 10
z := (x <> 5)
Result: z equals True (x is not equal to 5)
x := 12
z := (x != 12)
Result: z equals False (x is equal to 12)
Greater than or equal to (>=) example
x := 10
If (x >= 10)
Beep
Else
Quit
EndIf
Explanation: The computer beeps because the result of expression x >= 10 equals True (x equals 10). The Else statement is skipped. Quit does not end the macro.
Less than or equal to (<= example)
x := 20
If (x <= 10)
Beep
Else
Quit
EndIf
Explanation: The computer does not beep because the result of expression x <= 10 equals False (x is greater than 10). The Else statement is played. Quit ends the macro.
IN examples
z := 3 IN {1; 2; 3}
Result: z = True
z := 3 IN (1; 2; 4}
Result: z = False
z := {1; 2; 3} IN {1; 2; 3}
Result: z = True
z := {1; 2; 3} IN {1; 2; 3; 4}
Result: z = True
z := {1; 2; 3} IN {1; 2; 4}
Result: z = False
LIKE example
z := ("abc" LIKE "Abc")
Result: z = True.
Logical Operators
Logical operators are words that represent a logical relationship between conditions, or that invert a condition. The condition is the result of a relational expression. The operators are listed in order of precedence.
| Operator | Action |
| NOT | A unary operator that inverts the result of a relational expression. |
| AND | Combines two relational expressions. Each expression must be true for the logical expression to be True. |
| XOR | Combines two relational expressions. Only one expression can be true for the logical expression to be True. If both are true or both are false, the logical expression is False. The XOR operator is also named exclusive OR. |
| OR | Combines two relational expressions. Only one expression needs to be true for the logical expression to be True. The OR operator is also named inclusive OR. |
NOT example
x := 8
If ((x < 10) AND NOT (x = 5))
Beep
EndIf
Explanation: The result of the logical expression equals True (x is less than 10 AND NOT x is equal to 5, or x is not equal to 5).
AND example
x := 1
y := 2
z := ((x = 1) AND (y = 2))
Result: z equals True (the logical AND expression is True because both the relational expressions x = 1 and y = 2 are true).
XOR example
x := 1
y := 2
z := ((x = 0) XOR (y = 2))
Result: z equals True (only one relational expression is true).
z := ((x = 1) XOR (y = 2))
Result: z equals False (both relational expressions are true).
z := ((x = 0) XOR (y = 1))
Result: z equals False (both relational expressions are false).
XOR example in shorthand notation
x := 1
y := 2
If ((x = 0) XOR (y = 2))
Beep
EndIf
Explanation: The result of the logical XOR expression equals True because the relational expression x = 0 is false and the relational expression y = 2 is True.
OR example
x := 1
y := 2
z := ((x = 1) OR (y = 5))
Result: z equals True (the logical OR expression is True because the relational expression x = 1 is True).
Bitwise Operators
Bitwise operators are symbols that represent a bitwise operation on two integer operands. The operators are listed in order of precedence.
| Operator | Action |
| ~ | Bitwise unary NOT [complement of 1] toggles a binary value [1 to 0, and 0 to 1]. |
| & | Bitwise AND results in 1 if both operand bits are 1, and results in 0 if either of the operand bits are not 1. |
| | | Bitwise inclusive OR results in 1 if either operand is 1. Results in 0 if both operands are 0. |
| ^ | Bitwise exclusive OR (XOR) results in 0 if operands match, and 1 if operands do not match. |
| << | Shift bits left. |
| >> | Shift bits right. |
| <<< | Rotate bits left. |
| >>> | Rotate bits right. |
Unary NOT (~) example
| Decimal | Binary |
| ~-15 | (1111111111110001) |
| ____ | __________________ |
| 14 | (0000000000001110) |
Explanation: Bitwise unary NOT toggles bits from 1 to 0 and from 0 to 1.
AND (&) examples
x:=1000&31
Results: x equals 8
| Decimal | Binary |
| 1000 | (1111101000) |
| &31 | (0000011111) |
| ____ | ____________ |
| 8 | (0000001000) |
x := 65535 & 535
Result: x equals 535.
| Decimal | Binary |
| 65535 | 1111111111111111 |
| &535 | 0000001000010111 |
| _____ | ________________ |
| 535 | 0000001000010111 |
Explanation: Bitwise AND turns off bits (result is 0) if one operand is 0. Bits are left on (result is 1) if both operands are 1.
Inclusive OR (|) examples
x:=1000|27
Result: x equals 1019
| Decimal | Binary |
| 1000 | (1111101000) |
| |27 | (0000011011) |
| ____ | ____________ |
| 1019 | (1111111011) |
x := 65535 | 535
Result: x equals 65,535.
| Decimal | Binary |
| 65535 | 1111111111111111 |
| |535 | 0000001000010111 |
| _____ | ________________ |
| 65535 | 1111111111111111 |
Explanation: Bitwise OR turns on bits (result is 1) if one operand is 1. Bits are left off (result is 0) if both operands are 0.
Exclusive OR (^) examples
x:=1000^40
Result: x equals 960
| Decimal | Binary |
| 1000 | (1111101000) |
| ^40 | (0000101000) |
| ____ | _____________ |
| 960 | (1111000000) |
x := 65535 ^ 535
Result: x equals 65,000
| Decimal | Binary |
| 65535 | 1111111111111111 |
| ^ 535 | 0000001000010111 |
| _____ | ________________ |
| 65,000 | 1111110111101000 |
Explanation: Bitwise XOR turns on bits (result is 1) if the operands are different. It turns off bits (result is 0) if the operands are the same.
Shift left (<<) examples
x:=500<<1
Result: x equals 1000
| Decimal | Binary |
| 500 | (0111110100) |
| <<1 | |
| ____ | ____________ |
| 1000 | (1111101000) |
x := 65535 << 1
Result: x equals 131,070.
| Decimal | Binary |
| 65535 | 1111111111111111 |
| < < | |
| ___ | _______________ |
| 131,070 | 1111111111111110 |
Explanation: Shifts bits one position left, and inserts one 0 bit at the right end of the binary numeral. Multiplies the original value by 2.
Shift right (>>) examples
X:=1000>>1
Result: x equals 500
| Decimal | Binary |
| 1000 | (1111101000) |
| >>1 | |
| ____ | ____________ |
| 500 | (0111110100) |
x := 65535 >> 1
Result: x equals 32,767.
| Decimal | Binary |
| 65535 | 1111111111111111 |
| >> | |
| ____ | ____________ |
| 32,767 | 0111111111111111 |
Explanation: Shifts bits one position right, and inserts one 0 bit at the left end of the binary numeral. Divides the original value by 2.
Rotate left (<<<) examples
-2 <<< 2 is 5
x := -2147450881
Result: x equals 65535
| Decimal | Binary |
| -2147450881 | |
| <<< 1 | 10000000000000000111111111111111 |
| ____ | ________________________________ |
| 65535 | 1111111111111111 |
Rotate right (>>>) examples
x:=5
Result: x equals -2147483646
x := 65535 >>> 1
Result: x equals -2147450881
| Decimal | Binary |
| 65535 | >>>1111111111111111 |
| >>> 1 | |
| ____ | ________________________________ |
| -2147450881 | 10000000000000000111111111111111 |
Expressions
Expressions represent values, and can be arithmetic, numeric, measurement, relational, logical, bitwise, or a character string.
Macros support the following expressions:
Command and function calls can be used in an expression if they return a value.
Numeric Expressions
Numeric expressions are numeric constants or variables, or a combination of the two joined by a numeric operator. A numeric operator is a word or symbol that operates on numeric data, as explained earlier in this chapter.
Given that x equals 3, the following examples are valid numeric expressions.
5
Explanation: Numeric constant.
x
Explanation: Variable containing a numeric value.
x * 5
Explanation: Expression (multiply x and 5). The expression x * 5 is also an arithmetic expression.
+5
Explanation: Unary plus constant.
-(x + 10)
Explanation: Unary minus expression (negate the result of x plus 10).
Measurement Expressions
Measurement expressions are constants or variables containing a measurement value, or combination of the two joined by a numeric operator.
The following list contains valid units of measure.
| Unit of Measure | Measurement Type |
| " | Inches |
| i | Inches |
| c | Centimeters |
| m | Millimeters |
| p | Points (72 per inch) |
| w | WP unit (1200 per inch) |
A measurement expression is a number followed by one of the characters listed above. The character specifies the unit of measure for the number.
You can add and subtract measurement expressions as you do numeric expressions. When an operation is performed on measurement expressions that have different units of measure, the right operand is converted to the type of the left measurement operand.
Combining numeric expressions with measurement expressions can produce unexpected results.
You do not need to specify a unit of measure for command measurement expressions that follow DefaultUnits.
If you do not specify a unit of measure for a measurement expression, and DefaultUnits has not been encountered, the default unit of measure is WP units (1200 per inch).
Given that z equals 4i (inches), the following examples are valid measurement expressions.
5c
Explanation: Constant (5 centimeters).
z
Explanation: Variable that contains a measurement value of 4 inches.
z * 10i
Explanation: Expression (multiply z and 10 inches).
-z
Explanation: Unary minus (negative 4 inches).
Radix Base Conversions
The radix is the base of a number system. The following table contains the radix choices.
| Identifier | Description |
| x or h | Hexadecimal (radix is 16) |
| o | Octal (radix is 8) |
| b | Binary (radix is 2) |
x := 1Ah
Result: x equals 26
x := 1111b
Result: x equals 15
x := 44o
Result: x equals 36
All radix number values must begin with a number. Precede non-numeric hex digits with 0. For example,
x := 0Ah
Result: x equals 10
Character Expressions
Character expressions are character constants (letter, digit, or keyboard symbol) or variables. A character expression can also be a combination of the two concatenated by the plus operator (+), or a combination of the two separated by the minus operator (-), or compared by a relational operator such as > (greater than). Character constants and character constants assigned to variables must be enclosed in double quotation marks.
Enclose a character constant in single quotation marks to specify an ASCII numeric value (see PerfectScript CToN command). For example,
x := 'A'
Result: x equals 65.
x := 'A' + 'B'
Result: x equals 131 (65 + 66).
A character string with double quotation marks is enclosed with two sets of double quotation marks. For example,
x := "His name is ""John"" Doe"
Result: x equals His name is "John" Doe.
x := """John Doe"""
Result: x equals "John Doe" (outside quotation marks are always required).
The following examples are valid character expressions (notice the space after Joe and before Jr.).
"John Doe"
Explanation: Character string.
z := "Joe " + "Doe"
Explanation: Expression assigned to variable z (z equals John Doe).
x := z + ", Jr."
Explanation: Expression assigned to variable x (x equals John Doe, Jr.).
If you concatenate a character string and a number, the number is converted to a character string. If you concatenate a numeric character and a number, the numeric character is converted to a number and the two are added. For example,
x := "A" + 1
Result: x equals A1 (character string).
x := "1" + 1
Result: x equals 2 (number).
x := ("A" + (1 + 3))
Result: x equals A4 (the result of a mathematical operation (1+3=4) converted to a character string before being concatenated to A).
Compare the previous example with the following examples (operation precedence is left to right):
x := ("A" + 1 + 3)
Result: x equals A13 (character string—numbers converted and not added).
x := (1 + 3 + "A")
Result: x equals 4A (character string—numbers added and then converted to a character string).
Arithmetic Expressions
Arithmetic expressions are statements that represent arithmetic operations, or statements that contain two operands joined by an arithmetic operator. The operation result is a numeric value.
x := 1 + 2
Result: x equals 3.
x := 3 * 3
Result: x equals 9.
x := "2" * 3 * 4
Result: x equals 24 (2 converted to a number then multiplied).
x := "A" * 2
Result: error (cannot multiply letters and numbers).
Relational Expressions
Relational expressions are statements that represent a relational operation, or statements that contain two operands joined by a relational operator. The operation result equals True or False.
Given that x equals 5,
z := (x > 6)
Result: z equals False (5 is less than 6).
z := (x >= 5)
Result: z equals True (5 equals 5).
z := ("Ab" > "Bb")
Result: z equals False (Ab is less than, or comes before, Bb).
z := ("Ab" <> "Bb")
Result: z equals True (Ab is not equal to Bb).
Given that x equals "A", y equals "B", and z equals "a", the following expressions return True or False in variable w:
w := (x > y)
Result: w equals False (uppercase A is less than, or comes before, uppercase B).
w := (x > z)
Result: w equals True (uppercase A is greater than, or comes after, lowercase a).
Logical Expressions
Logical expressions are statements that represent logical operations, or statements that contain two relational expressions joined by a logical operator. The operation result equals True or False.
Given that x equals 10, y equals 5, and z equals 20, the following expressions return True or False in variable w:
w := ((x > y) AND (y < z))
Result: w equals True (both relational expressions are true).
w := ((x < y) AND (y < z))
Result: w equals False (first relational expression is false).
w := NOT(y > z)
Result: w equals True (5 is not greater than 20).
w := ((x > 5) AND (y < 20) AND (z = 20))
Result: w equals True (all relational expressions are true).
w := (((x < 5) AND (y > 20)) OR (z = 20))
Result: w equals True (z = 20 is true).
w := (((x < 5) AND (y > 20)) OR NOT (z = 20))
Result: w equals False (all relational expressions are false).
Bitwise Expressions
Bitwise expressions are statements that represent bitwise operations, or statements that contain two operands joined by a bitwise operator. The operation result is a numeric value.
Bitwise NOT (~) example
x := ~(-15)
Result: x equals 14 (complement of 1).
x := ~(-15) + 1
Result: x equals 15 (complement of 2).
Bitwise AND (&) example
x := 65535 & 535
Result: x equals 535.
Bitwise inclusive OR (|) example
x := 65535 | 535
Result: x equals 65,535.
Bitwise XOR (^) example
x := 65535 ^ 535
Result: x equals 65,000.
Bitwise shift left (<<) example
x := 65535 << 1
Result: x equals 131,070.
Bitwise shift right (>>) example
x := 65535 >> 1
Result: x equals 32,767.
Bitwise rotate left (<<<) example
x := -2147450881 <<< 1
Result: x equals 65535
Bitwise rotate right (>>>) example
x := 65535 >>> 1
Result: x equals -2147450881