Skip to content

Latest commit

 

History

History
119 lines (87 loc) · 2.31 KB

operator_precedence.md

File metadata and controls

119 lines (87 loc) · 2.31 KB

Home

Operator precedence

Precedence Operator Description
1 . Scope
1 [] Subscript
2 << Bitwise left shift
2 >> Bitwise right shift
3 * Multiplication
3 / Division
3 % Remainder
4 + Addition
4 - Subtraction
5 | Bitwise OR
5 & Bitwise AND
5 ^ Bitwise XOR
5 ~ Binary ones complement
5 >>> Unsigned right shift

Scope example

object animal 5;

int animal.x 1;
animal.x = 100;

Subscript example

int array 10 = 0;
int currentIndex = 0;
int currentValue = 5;

# Value of array at index 0 will equal 5 after assignment.
array[0] = array[currentIndex] + currentValue;

Bitwise left shift example

int MULTIPLIER = 200 << 24;
int shiftResult = (16 * 8) << 4;

Bitwise right shift example

int RIGHT_MULTIPLIER = -200 >> 24;
int secondShift = (32 / 2) >> 16;

Multiplication example

int area = 5 * 5;

Division example

int perimeter = 250 / 25;

Remainder example

int remainder = 1050 % 6;

Addition example

int sum = 5 + 25 + 125;

Subtraction example

int difference = 1000 - 100 - 10;

Bitwise OR example

# orResult equals 248 after assignment.
int orResult = 72 | 184;

Bitwise AND example

# andResult equals 8 after assignment.
int andResult = 72 & 184;

Bitwise XOR example

# xorResult equals 159 after assignment.
int xorResult = 31 ^ 128;

Binary ones complement example

# onesComplementResult equals -51 after assignment.
int onesComplementResult = 0 ~ 50;

Unsigned right shift example

# unsignedRightShiftResult equals 30 after assignment.
int unsignedRightShiftResult = 123 >>> 2;