Perform integer division using multiplication [duplicate]
This question already has an answer here: Why does GCC use multiplication by a strange number in implementing integer division? 4 answers Looking at x86 assembly produced by a compiler, I noticed that (unsigned) integer divisions are sometimes implemented as integer multiplications. These optimizations seem to follow the form value / n => (value * ((0xFFFFFFFF / n) + 1)) / 0x100000000 For example, performing a division by 9: 12345678 / 9 = (12345678 * 0x1C71C71D) / 0x100000000 A division by 3 would use multiplication with 0x55555555 + 1 , and so on. Exploiting the fact that the mul instruction