ROBOTC, as the name suggests, is a C-based programming language. As such, it retains much of the standard C programming language functionality, including C's handling of the various mathematical and logical operators.
Whenever any operators are used in C programming, they are executed from left to right starting with operations level 1 and proceeding up the levels until operations level 14. Be careful when creating complex statements, as they might not execute in the order that you wish.
Notice that the standard mathematical order of operations (multiplication before addition, etc.) is preserved here within the larger hierarchy.
Operations level 1
| Operator | Syntax | Explanation |
|---|---|---|
| ++ | x++ | A unary operator that increases the value of "x" by one. This operand does not affect the value of "x" in the current expression.(e.g. y= x++ sets "y" to the value of "x", not "x+1," even though "x" is then set to "x+1") |
| -- | x-- | A unary operator that decreases the value of "x" by one. This operand does not affect the value of "x" in the current expression. |
Operations Level 2
| Operator | Syntax | Explanation |
|---|---|---|
| ++ | ++x | A unary operator that increases the value of "x" by one. This operand affects the value of x in the current expression.(e.g. y= ++x sets "y" to the value of "x+1", not "x") |
| -- | --x | A unary operator that decreases the value of "x" by one. This operand affects the value of x in the current expression. |
| + | +x | A unary operator that makes the value of "x" positive |
| - | -x | A unary operator that switches the sign of "x" from positive to negative or from negative to positive. |
| ! | !x | A logical operator that returns a boolean value that is the opposite of "x" (If "x" is true, then "!x" returns false) |
Operations Level 3
| Operator | Syntax | Explanation |
|---|---|---|
| / | a / b | An operator that returns the value of "a divided by b" |
| * | a * b | An operator that returns the value of "a multiplied by b" |
| % | a % b | An operator that returns the value of "the remainder of a divided by b" |
Operations Level 4
| Operator | Syntax | Explanation |
|---|---|---|
| + | a + b | An operator that returns the value of "a plus b" |
| - | a - b | An operator that returns the value of "a minus b" |
Operations Level 5
Also known as "bitwise operators" for modifying the individual memory bits (binary form) of a variable.
| Operator | Syntax | Explanation |
|---|---|---|
| >> | a >> b | A bitwise shift to the right. This operation takes the memory bits of "a" (the binary form of "a") and moves all of them "b" places to the right, dropping any values that fall off and replacing them with zero. This is mathematically equivalent to dividing by 2^b |
| << | a << b | A bitwise shift to the left. This operation takes the memory bits of "a" (the binary form of "a") and moves all of them "b" places to the left, dropping any values that fall off and replacing them with zero, except for the sign bit, which is preserved to keep negative numbers negative. This is mathematically equivalent to multiplying by 2^b |
Operations Level 6
Also known as "boolean operators" for returning boolean values
| Operator | Syntax | Explanation |
|---|---|---|
| < | a < b | A logical statement that returns "true" if "a" is less than "b" |
| <= | a <= b | A logical statement that returns "true" if "a" is less than or equal to "b" |
| > | a > b | A logical statement that returns "true" if "a" is greater than "b" |
| >= | a >= b | A logical statement that returns "true" if "a" is greater than or equal to "b" |
Operations Level 7
Also known as "boolean operators" for returning boolean values
| Operator | Syntax | Explanation |
|---|---|---|
| == | a == b | A logical statement that returns "true" if "a" is equal to "b" |
| != | a != b | A logical statement that returns "true" if "a" NOT equal to "b" |
Operations Level 8
Also known as "bitwise operators" for modifying the individual memory bits (binary form) of a variable.
| Operator | Syntax | Explanation |
|---|---|---|
| & | a & b | A bitwise operator AND. Compares the memory bits (binary form) of "a" and "b" and outputs a number that has the length of the larger of the two, and a 1 in every slot that both "a" and "b" have a 1, and 0 everywhere else. (logical "And") |
Operations Level 9
Also known as "bitwise operators" for modifying the individual memory bits (binary form) of a variable.
| Operator | Syntax | Explanation |
|---|---|---|
| ^ | a ^ b | A bitwise operator ExclusiveOR. Compares the memory bits (binary form) of "a" and "b" and outputs a number that has the length of the larger of the two, and a 0 in every slot that both "a" and "b" have a 1 or a 0, and 1 everywhere else. Can also be understood as a 1 in ever bit where either a or b had a 1 but not both.(Logical Exclusive Or) |
Operations Level 10
Also known as "bitwise operators" for modifying the individual memory bits (binary form) of a variable.
| Operator | Syntax | Explanation |
|---|---|---|
| | | a | b | A bitwise operator OR. Compares the memory bits (binary form) of "a" and "b" and outputs a number that has the length of the larger of the two, and a 1 in every slot that either or both "a" and "b" have a 1, and 0 everywhere else. (Logical Or) |
Operations Level 11
| Operator | Syntax | Explanation |
|---|---|---|
| && | a && b | Returns "true" if both "a" and "b" are also true |
Operations Level 12
| Operator | Syntax | Explanation |
|---|---|---|
| || | a || b | Returns "true" if either "a" or "b" is true |
Operations Level 13
| Operator | Syntax | Explanation |
|---|---|---|
| ?: | a ? b : c | Ternary operations: see Tertiary operators |
Operations Level 14
| Operator | Syntax | Explanation |
|---|---|---|
| = | a = b | Assigns the value of "b" to "a" |
| += | a += b | Assigns the value of "a + b" to "a" |
| -= | a -= b | Assigns the value of "a - b" to "a" |
| /= | a /= b | Assigns the value of "a / b" to "a" |
| *= | a *= b | Assigns the value of "a * b" to "a" |
| %= | a %= b | Assigns the value of "a % b" to "a" |
| <<= | a <<= b | Assigns the value of "a << b" to "a" |
| >>= | a >>= b | Assigns the value of "a >> b" to "a" |
| &= | a &= b | Assigns the value of "a & b" to "a" |
| ^= | a ^= b | Assigns the value of "a ^ b" to "a" Remember that this is not telling ROBOTC to take "a to the power of b" |
| |= | a |= b | Assigns the value of "a |= b" to "a" |