Boolean and arithmetic operators
Programming languages can perform maths on the numbers they store in variableA named storage location. The value of a variable can change, constants and arrayA set of data values of the same type, stored in a sequence in a computer program. Also known as a list. .
Mathematical operations use operandData that is manipulated by the CPU/processor according to the given opcode, eg in the instruction ADD 3, the operand is 3. as input and carry out a mathematical function based on the .
Operators represent computations like addition, multiplication and division. The values the operator works on are called operands.
Common mathematical operators used in programming include:
| Operator | Name and description | Example |
| + | Addition | 2 + 2 = 4 |
| – | Subtraction | 4 – 2 = 2 |
| / | Division | 8 / 4 = 2 |
| * | Multiplication | 4 * 8 = 32 |
| ^ | Exponentiation: When one number increases exponentially (the number of times) to another. The repeated multiplication of a number by itself. | 2 ^ 4 = 16 (2 * 2 * 2 * 2 = 16, or 24) |
| MOD | Modulus: The remainder that is left over when a number is divided by another. Some programming languages will use the % symbol for MOD. | 16 MOD 3 = 1 (16 / 3 = 5, with 1 left over) |
| DIV | Integer division: Used to find the quotient (integer number before the decimal point) after division. Python uses // for this. | 100 DIV 3 = 33 (actual value 33.333333333 repeating) |
| Operator | + |
|---|---|
| Name and description | Addition |
| Example | 2 + 2 = 4 |
| Operator | – |
|---|---|
| Name and description | Subtraction |
| Example | 4 – 2 = 2 |
| Operator | / |
|---|---|
| Name and description | Division |
| Example | 8 / 4 = 2 |
| Operator | * |
|---|---|
| Name and description | Multiplication |
| Example | 4 * 8 = 32 |
| Operator | ^ |
|---|---|
| Name and description | Exponentiation: When one number increases exponentially (the number of times) to another. The repeated multiplication of a number by itself. |
| Example | 2 ^ 4 = 16 (2 * 2 * 2 * 2 = 16, or 24) |
| Operator | MOD |
|---|---|
| Name and description | Modulus: The remainder that is left over when a number is divided by another. Some programming languages will use the % symbol for MOD. |
| Example | 16 MOD 3 = 1 (16 / 3 = 5, with 1 left over) |
| Operator | DIV |
|---|---|
| Name and description | Integer division: Used to find the quotient (integer number before the decimal point) after division. Python uses // for this. |
| Example | 100 DIV 3 = 33 (actual value 33.333333333 repeating) |