GCSE Link: 2.03 (Operations)

Again, there is nothing new on this page. Everything below has been copied over from the GCSE link.

Operators in Computer Science are just like operators in Maths: they are symbols which perform certain functions on data.

Arithmetic operators work on numbers. Most of them are basic Maths.

Table 1 shows the arithmetic operators.

Table 1

Name Operator Example Result
Addition + 3 + 6 9
Subtraction - 7 - 2 5
Multiplication * 5 * 8 40
Division / 10 / 4 2.5
Integer (floor) division // (or DIV) 11 / 3 3
Modulus (remainder) % (or MOD) 12 % 5 2

Comparison operators give a boolean result.

Table 2 shows the comparison operators.

Table 2

Name Operator True False
Equal to == (or =) 7 == 7 7 == 8
Not equal to != (or ) 5 != 8 5 != 5
Less than < 4 < 6 4 < 3
Greater than > 6 > 5 6 > 6
Less than or equal to <= (or ) 3 <= 7 3 <= 2
Greater than or equal to >= (or ) 8 >= 8 8 >= 9

Boolean operators work on booleans.

Table 3 shows the boolean operators.

Table 3

Operator C# Symbol True False
AND && (or & for bitwise) true && true false && false
false && true
true && false
OR || (or | for bitwise) false || true
true || false
true || true
false || false
XOR ^ (same for bitwise) false ^ true
true ^ false
false ^ false
true ^ true
NOT ! (or ~ for bitwise) !false !true



Evaluate the expression ((10 * 6 / 4) <= (1 + 2 * 5)) ^ ((17 % 5 + 3) != (14 - 6))

This evaluates to (15 <= 11) ^ (5 != 8), which is false ^ true, which is true.