Difference between revisions of "Operators"
(Created page with "There are five types of mathematical operator, and four types of bitwise operator.<br /> <h2>Mathematical operators</h2> *Addition - performed using the "+" operator; adds val...") |
(Tabled and added Increment and Decrement) |
||
Line 1: | Line 1: | ||
There are five types of mathematical operator, and four types of bitwise operator.<br /> | There are five types of mathematical operator, and four types of bitwise operator.<br /> | ||
<h2>Mathematical operators</h2> | <h2>Mathematical operators</h2> | ||
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | ! Operation !! Character used !! Description !! Example | |
− | + | |- | |
− | + | | Addition || Performed using the "+" operator || Adds values together. || <tt>A + B = 12</tt> | |
+ | |- | ||
+ | | Subtraction || Performed using the "-" operator || Subtracts values. || <tt>A - B = 8</tt> | ||
+ | |- | ||
+ | | Multiplication || Performed using the "*" operator || Multiplies values together. || <tt>A * B = 20</tt> | ||
+ | |- | ||
+ | | Division || Performed using the "/" operator || Divides values. || <tt>S / B = 5</tt> | ||
+ | |- | ||
+ | | Increment || Performed using the "++" operator || Adds 1 to a variable and saves the variable. || <tt>A++ = 11</tt> | ||
+ | |- | ||
+ | | Decrement || Performed using the "--" operator || Subtracts 1 from a variable and saves the variable. || <tt>B-- = 9</tt> | ||
+ | |- | ||
+ | | Modulus || Performed using the "%" operator || Finds the remainder of a division between values. || <tt>10 % 3 = 1</tt> | ||
+ | |} | ||
<h2>Bitwise operators</h2> | <h2>Bitwise operators</h2> | ||
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | ! Operation !! Character used !! Description !! Example | |
− | + | |- | |
+ | | AND || Performed using "&" or "&&" || Returns true if both inputs are true. || true && false = false | ||
+ | |- | ||
+ | | OR || performed using "<nowiki>|</nowiki>" or "<nowiki>||</nowiki>" || returns true if one or both inputs are true. || <tt>true <nowiki>||</nowiki> false = true</tt> | ||
+ | |- | ||
+ | | XOR || Performed using "^" || Returns true if both inputs are different. || <tt>true ^ false = true</tt> | ||
+ | |- | ||
+ | | NOT || performed using "!" || Returns false if true, or true if false. || <tt><nowiki>!</nowiki>true = false</tt> | ||
+ | |} |
Revision as of 12:18, 15 December 2016
There are five types of mathematical operator, and four types of bitwise operator.
Mathematical operators
Operation | Character used | Description | Example |
---|---|---|---|
Addition | Performed using the "+" operator | Adds values together. | A + B = 12 |
Subtraction | Performed using the "-" operator | Subtracts values. | A - B = 8 |
Multiplication | Performed using the "*" operator | Multiplies values together. | A * B = 20 |
Division | Performed using the "/" operator | Divides values. | S / B = 5 |
Increment | Performed using the "++" operator | Adds 1 to a variable and saves the variable. | A++ = 11 |
Decrement | Performed using the "--" operator | Subtracts 1 from a variable and saves the variable. | B-- = 9 |
Modulus | Performed using the "%" operator | Finds the remainder of a division between values. | 10 % 3 = 1 |
Bitwise operators
Operation | Character used | Description | Example |
---|---|---|---|
AND | Performed using "&" or "&&" | Returns true if both inputs are true. | true && false = false |
OR | performed using "|" or "||" | returns true if one or both inputs are true. | true || false = true |
XOR | Performed using "^" | Returns true if both inputs are different. | true ^ false = true |
NOT | performed using "!" | Returns false if true, or true if false. | !true = false |