Steve's solutions cover the case that high nibble could hold some bits at 1 and masks to zero. Mine is based on the assumption that high nibbles will always be 0.

It would also be interesting to know which way is less memory hungry.

Ioannis