Created
April 3, 2013 15:31
-
-
Save scturtle/5302263 to your computer and use it in GitHub Desktop.
number of last 0 in 32bit binary number from http://www.matrix67.com/blog/archives/3985
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c=(0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, | |
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9) | |
def num_of_last_0_in_32bit(v): | |
return c[(0xffffffff & ((v&-v) * 0x077CB531)) >> 27] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment