ビット演算まとめ

http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=bitManipulation

n & (n-1)
long long n;
there exists m in N n = 2^mの判定。

__builtin_ctz(n)
unsigned int n;
count trailing zeros
__builtin_ctz(n) = k * 2^m, k and 2 are coprimeなるm
__builtin_ctz(n) = LSB(n)

__builtin_clz(n)
unsigned int n;
count leading zeros
sizeof(n) – __builtin_clz(n) = argmin x < 2^i

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>