ensurePowerOfTwo is poorly named (it's a round up to power of two) and assumes 32-bit integers...