Yeah that code is pretty exciting. But it still doesn't work for the situation where the width is 5 less than a power of 2. Right now I have a for loop in my code that checks for for this situation. It isn't that expensive an operation it would just be nice if I can have a small algorithm take care of this exception without looping through powers of 2.