in reply to bit pattern to bit position mapping

I suggest getting rid of the function code and inlining the grep. This saves the overhead of the function call, at least. You could use -P or your favorite macro processor to make it look like a function call.