3. Operators

3.1. Basic arithmetic operators

1int a = 1 + 1;
2int b = 1 - 1;
3int c = 1 * 2;
4int d = 2 / 4;
5int e = 4 % 3;

3.2. Unary operators

1int a = 10;
2int b = --a;
3int c = a--;
4int d = ++a;
5int e = a++;

3.3. Compound assignment operators

 1int a = 10;
 2a = a + 4;
 3
 4int b = 10;
 5b += 4;
 6
 7int c = 10;
 8c = c - 4;
 9
10int d = 10;
11d -= 4;
12
13int e = 10;
14e = e * 2;
15
16int f = 10;
17f *= 2;
18
19int g = 10;
20g = g / 2;
21
22int h = 10;
23h /= 2;

3.4. Bitwise operators

1var a = 42;
2var b = 15;
3
4var q = ~42; // bitwise not
5var r = a | b; // bitwise or
6var s = a & b; // btiwise and
7var t = a ^ b; // bitwise XOR
1var a = 1;
2
3var x = a << 1;
4var y = a << 2;
5var z = a << 3;
1var a = 8;
2
3var x = a >> 1;
4var y = a >> 2;
5var z = a >> 3;
1var a = -1;
2
3var x = a >>> 8;
4var y = a >>> 16;
5var z = a >>> 24;

3.5. Relational operators

1var num1 = 4;
2var num2 = 2;
3
4var a = num1 == num2;
5var b = num1 != num2;
6var c = num1 > num2;
7var d = num1 < num2;
8var e = num1 >= num2;
9var f = num1 <= num2;

3.6. Boolean logical operators

 1var a = false;
 2var b = false;
 3
 4var a_or_b = a | b;
 5var a_and_b = a & b;
 6var a_xor_b = a ^ b;
 7var not_a = !a;
 8var a_short_or_b = a || b;
 9var a_short_and_b = a && b;
10var ternary = a ? true : false;

3.7. Parentheses

1var result1 = 4 + 2 * 2;
2var result2 = (4 + 2) * 2;