Hei Charles,

Any number of these bit twiddling hacks here:
	http://www-graphics.stanford.edu/~seander/bithacks.html

will translate straight to Ruby. I guess the lookup table approach is
easy to implement and reasonably fast.

Another strategy would be to implement this in C and load it as an
extension. Make sure this is really the hotspot of your code before
optimizing...

kaspar