Hacker News new | ask | show | jobs
by besselheim 3222 days ago
Assuming 32-bit unsigned integers (but similarly for other integer sizes), multiplying by 0x11111111 and shifting right 28 bits would give a function of period 15, at least for inputs between 1 and 0x1000000e inclusive. Faster than dividing by 15.
1 comments

You're absolutely on the right track with a (wrapping) multiply and a shift right, but the constants aren't quite right.