I want to create a bitmask for the most right continuous range of set bits. For example 01010110 -> 00000110. Is (x & ~(x + (x & -x))) the best way to do that or is there a better solution? #followerpower
-
-
Replying to @oe1cxw
I defer to Knuth, 4A.7.1.3 formula 43, which suggests: x & ~[ (x|(x-1)) + 1] This is probably of the same complexity as your solution.
1 reply 0 retweets 3 likes -
Replying to @babbageboole @oe1cxw
Or possibly lower complexity, I'm not sure. Is increment/decrement easier than general addition?
1 reply 0 retweets 1 like
Replying to @babbageboole
Thanks, that's great! Re complexity: On AMD processors with TBM the whole expression (x|(x-1)) is a single instruction. (BLSFILL)
4:15 AM - 28 Apr 2018
0 replies
0 retweets
1 like
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.