What does this bit-manipulating function do?
2015-03-16 14:27
369 查看
http://stackoverflow.com/questions/8637142/what-does-this-bit-manipulating-function-do
unsigned long ccNextPOT(unsigned long x){ x = x - 1; x = x | (x >> 1); x = x | (x >> 2); x = x | (x >> 4); x = x | (x >> 8); x = x | (x >>16); return x + 1; } bit-manipulation
| |||||||||||||
|
2 Answers
activeoldestvotesup vote2down vote | The OR and SHIFT statements fills with ones all bits of xto the right of most significant bit (up to 32 bits). Together with the pre-decrement and post-increment statements, this computes (as the function name suggets) the next power-of-two number, equal or greater than the given number (if xis greater than 0 and less than 2^32)
| ||||
|
up vote0down vote | This function rounds x up to the next highest power of 2. It's exactly the code in hereunsigned int v; // compute the next highest power of 2 of 32-bit v v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++;
| |||
add a comment |
相关文章推荐
- What does ENABLE_BITCODE do in xcode 7?
- What does the PF function do in Primefaces
- Mongoose - What does the exec function do?
- What does the SQLERRM Function do
- What does the SQLCODE Function do
- Does perl have a round function? What about ceil() and floor()?
- Android 4.2 Feature Highlight: So, What Is This Miracast Thing And How Does It Work, Anyway?
- What does a Scrum Master do?
- Your ID is under ID protection. Your current version does not support this function. Please download the latest Simplified Chine
- In Javascript, what does this underscore mean?
- What does functools.wraps do?
- [stackoverflow翻译] “yield” 关键字有什么用?what-does-the-yield-keyword-do
- What Does an Office Messenger Do?
- What does _imp_<Function> mean?
- What does if __name__ == “__main__”: do?
- What does addScalar do?
- What does functools.wraps do?
- ccah-500 第11题What does CDH packaging do on install to facilitate Kerberos security setup
- what does “static int function(…) __acquires(..) __releases(…){” mean?
- Self summary: What does typical CNN do and What is Soft-max?