algorithm - How to count trailing zeros in a binary representation of an integer number with C# -


how count efficiently number of trailing zeros in binary representation of integer number?

here's nice, quick , easy implementation:

public static int numberoftrailingzeros(int i) {     return _lookup[(i & -i) % 37]; }  private static readonly int[] _lookup =     {         32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17,         0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18     }; 

(taken http://graphics.stanford.edu/~seander/bithacks.html#zerosonrightmodlookup.)


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -