Oh, just a follow-on, here's a small perfect hash function for quadratic residues modulo 256. It does the same thing as the sq_res_100[] table. static bool mod256(unsigned x) { x %= 256; return !(x*0x105fd & ~(x*0x502a8) & 0xff14082a); }