x = x * 2;
x = x * 64;
equals:
x = x << 1; // 2 = 21
x = x << 6; // 64 = 26
2. If in addition to the previous one of the multiple values, you can use the right shift operation to accelerate 350%.
x = x / 2;
x = x / 64;
equals:
x = x >> 1;// 2 = 21
x = x >> 6;// 64 = 26
x = int(1.232)
equals:
x = 1.232 >> 0;
var t:
t = a;
a = b;
b = t;
equals:
a = a^b;
b = a^b;
a = a^b;
i = -i;
equals:
i = ~i + 1; // NOT
equals:
i = (i ^ -1) + 1; // XOR
6. Take the remainder, if the divisor is a multiple of 2, you can use the AND operation to speed up the 600%.
x = 131 % 4;
equals:
x = 131 & (4 - 1);
isEven = (i % 2) == 0;
equals:
isEven = (i & 1) == 0;
i = x < 0 ? -x : x;
equals:
i = (x ^ (x >> 31)) - (x >> 31);
equals:
i=x^(~(x>>31)+1)+(x>>31);
eqSign = a * b > 0;
equals:
eqSign = a ^ b > 0;
var bitColor = 0xff00cc;
var r = bitColor >> 16;
var g = bitColor >> 8 & 0xFF;
var b = bitColor & 0xFF;
var r = 0xff;
var g = 0x00;
var b = 0xcc;
var bitColor:uint = r << 16 | g << 8 | b;