in reply to More simple math.
sub f { 0x32107654ba98fedc >> (4*pop) & 0xf }
Shame about its limits. (My fault for providing a simplified example!)