Add dynamic version of next/prev power of 2 and unit tests