Bitwise Operators in ActionScript - Part 1

Notes:

Bitwise Operators in ActionScript Programming Language - Part 1:

Bitwise Operators:
- are used to perform operations on bits.

- Bitwise operators convert the given decimal number(s) to their binary equivalent number,
and then they perform the operations on bits of those binary equivalent number(s).

&: Bitwise And operator:
If both LHS and RHS are 1 then the result will be 1, in all other cases result will be 0
P Q P & Q
1 1 1
1 0 0
0 1 0
0 0 0

|: Bitwise Or operator:
If both LHS and RHS are 0 then the result will be 0, in all other cases result will be 1
P Q P | Q
1 1 1
1 0 1
0 1 1
0 0 0

^: Bitwise Exclusive Or operator:
If both LHS and RHS are same then the result will be 0, otherwise the result will be 1
P Q P ^ Q
1 1 0
1 0 1
0 1 1
0 0 0

Example code:

trace("Bitwise operators");
trace(1 & 1); // 1
trace(1 & 0); // 0
trace(0 & 1); // 0
trace(0 & 0); // 0

trace(1 | 1); // 1
trace(1 | 0); // 1
trace(0 | 1); // 1
trace(0 | 0); // 0

trace(1 ^ 1); // 0
trace(1 ^ 0); // 1
trace(0 ^ 1); // 1
trace(0 ^ 0); // 0

trace(2 & 2); //2
trace(2 & 5); //0
trace(2 | 5); //7
trace(5 ^ 5); // 0
trace(2 ^ 5); // 7