I'm trying to figure out the fastest way to copy bits according to a given mask, and put them together, for example:
| | |
x = 0x01110001
| | |
mask = 0x00100101
| | |
result=0x101----- (- doesn't matter)
basically I want to copy all the bits for which there is a 1
in the mask and shift them together.
I can only think of a slow and tedious way to copy each bit and shift it.
So the question is there a faster strait forward way to do it for all the bits simultaneously?