Two tricks of making integer computation faster in Delphi. 1. Two integers a and b, to compute a mod b, where b is power of two (two, four, eight ... etc)... in delphi, you write result := a mod b; in this case, to make it faster, you can write result := a and (b - 1); // b >= 2, and power of 2. 2. Two integers a (a >= 0) and b, to compute a div b, where b is power of two (two, four, eight ... etc)... in delphi, you write result := a div b; in this case, to make it faster, you can write c := fun(b); // fun returns the integer(log2(b)) result := a shr c; // where b >= 2, and power of 2 // returns the left-most significant digit. function fun(b: integer): integer; assembler; register; asm bsr eax, eax end; if (a < 0), it can be reworked as result = -((-a) shr c)