OK, guys, I know what I want to do, but I don't know if it already exists (as a function or theoretically) or how to phrase it, so I need your help :
- Let's say we've got a binary number : (msb)
10101110(lsb) - Starting from bit X, I want to zero-out all other bits (going left), as soon as the first zero bit is encountered.
- Do that as fast as possible, with the absolute minimum number of operations and CPU cycles needed
An example :
- Number = 10101110, Starting position = 1 (bit at place 1 = 1)
- position++ - bit at place 2 = 1, keep going
- position++ - bit at place 3 = 1, keep going
- position++ - bit at place 4 = 0, oops... zero encountered... now, everything has to be zero-ed out.
So, the final result of our imaginary function CROPLEFT(X,POS), where X=10101110, and POS=1, would return 00001110.
Any ideas?