Jan 20, 2009

I want to see if all the ones in a number appear on the right side of the number and all zeros appear on the left, how can I do this most efficiently?

I want to see if all the ones in a number appear on the right side of the number and all zeros appear on the left, how can I do this most efficiently? (i.e. 00000111 is true but 100010 is false)
Check X&(x+1)==0, only work for 00001111 mode not 11110000mode
For all 1’s in the left, check ~x&(~x+1)==0

No comments:

Post a Comment