原创 短小精悍的BIT TWIDDING HACKS

2011-4-9 20:55 2674 11 11 分类: 软件与OS

引用:

下面地址:

http://www-graphics.stanford.edu/~seander/bithacks.html#ParityNaive


介绍在程序开发中,需要对位进行特别操作的 精悍算法和技巧!

、对此共享给大家!


Bit Twiddling Hacks


Contents

Compute the integer absolute value (abs) without branchingCompute the minimum (min) or maximum (max) of two integers without branchingDetermining if an integer is a power of 2Sign extending Conditionally set or clear bits without branchingConditionally negate a value without branchingMerge bits from two values according to a maskCounting bits set Computing parity (1 if an odd number of bits set, 0 otherwise) Swapping Values Reversing bit sequences Modulus division (aka computing remainders) Finding integer log base 2 of an integer (aka the position of the highest bit set) Find integer log base 10 of an integerFind integer log base 10 of an integer the obvious wayFind integer log base 2 of a 32-bit IEEE floatFind integer log base 2 of the pow(2, r)-root of a 32-bit IEEE float (for unsigned integer r)Counting consecutive trailing zero bits (or finding bit indices) Round up to the next highest power of 2 by float castingRound up to the next highest power of 2Interleaving bits (aka computing Morton Numbers) Testing for ranges of bytes in a word (and counting occurances found) Compute the lexicographically next bit permutation

文章评论0条评论)

登录后参与讨论
我要评论
0
11
关闭 站长推荐上一条 /2 下一条