Difference between revisions of "MC-Basic Operators"

From SoftMC-Wiki
Jump to: navigation, search
m (changed category)
m (Bit-wise Operators: Added shr and shl references)
Line 126: Line 126:
 
|align="center"|1
 
|align="center"|1
 
|-
 
|-
|Bitwise And
+
|Bitwise AND
 
|align="center"|BAND
 
|align="center"|BAND
 
|align="center"|2
 
|align="center"|2
 
|-
 
|-
|Bitwise Or
+
|Bitwise OR
 
|align="center"|BOR
 
|align="center"|BOR
 
|align="center"|3
 
|align="center"|3
 
|-
 
|-
|Bitwise Exclusive Or
+
|Bitwise Exclusive OR
 
|align="center"|BXOR
 
|align="center"|BXOR
 
|align="center"|4
 
|align="center"|4
 +
|-
 +
|Shift left
 +
|align="center"|[[Axystems:MC-Basic:SHL|SHL]]
 +
|align="center"|
 +
|-
 +
|Shift right
 +
|align="center"|[[Axystems:MC-Basic:SHR|SHR]]
 +
|align="center"|
 
|}
 
|}
 
   
 
   

Revision as of 13:13, 2 August 2012

The tables shown below list the different types of operators, and their relative precedence. Arithmetic operators have the highest precedence, followed by Relational, Logical and Bit-wise operators. The relative precedence of the operators within each group is noted in the tables. Parentheses may be used to force a different order of expression processing because parentheses have the highest precedence. The “+” operator can be used to concatenate strings, and the “=” operator can be used to copy strings. The other operators have no applicability with strings.

The “=” operator can also be utilized to copy the entire values of an array to another array (matching in size and number of dimensions) through a single assignment statement. Other operators have no applicability with whole arrays.

Arithmetic Operators

Operation Symbol Relative Precedence
Exponentiation ^ 1
Negation/N/A minus - 2
Multiplication * 3
Division / 3
Modulus MOD 4
Addition + 5
Subtraction - 5

Relational Operators

Relational operators provide a method whereby two values may be compared. The result of the comparison is either TRUE (1) or FALSE (0). The operators are listed below; all Relational Operators have the same level of precedence, and relational operators have lower precedence than arithmetic operators. Relational operators may be used with any type of variable or value, including strings. String comparisons are made character-by-character, starting with the first character in each string, thus the string “de” is greater than the string “abc”. Character comparisons are made according to the value of the ASCII character codes for the respective characters.

Operation Symbol Relative Precedence
Equality = 1
Inequality <> 1
Less than < 1
Greater than > 1
Less than or equal to <= 1
Greater than or equal to >= 1

Logical Operators

Logical operators perform tests on multiple relations, and return a True (nonzero) or False (zero) value to be used in making a decision. Logical operators have lower precedence than Relational operators. They may be used on integer operands only (including the results of relational expressions).

Operation Symbol Relative Precedence
Complement NOT 1
And AND 2
Or OR 3
Exclusive Or XOR 4

Bit-wise Operators

Bitwise operators perform bit manipulations on integer operands only. The result of the operation is a Long.

Operation Symbol Relative Precedence
Bitwise complement BNOT 1
Bitwise AND BAND 2
Bitwise OR BOR 3
Bitwise Exclusive OR BXOR 4
Shift left SHL
Shift right SHR