Skip to content

Instantly share code, notes, and snippets.

@scturtle
Created April 3, 2013 15:31
Show Gist options
  • Save scturtle/5302263 to your computer and use it in GitHub Desktop.
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
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