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;
}
|
|
asked Dec 26 '11 at 15:45
|
|
|
|
|
The OR and SHIFT statements fills with ones all bits of x to 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 x is greater than 0 and less than 2^32)
|
answered Dec 26 '11 at 16:54
|
|
|
|
|
This function rounds x up to the next highest power of 2. It's exactly the code in here
unsigned 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++;
|
|
answered Jul 31 '13 at 13:45
|
|
|
|
最新文章
- 修改TNSLSNR的端口
- MOTION-MATCHING IN UBISOFT’S FOR HONOR翻译
- 单身狗进化——求n!的位数
- C++基础知识之vector
- Windows技巧 - 右键菜单【在此处打开bash】
- (转)CSS3 @font-face
- 【转】简单的 Laravel 5 REST API
- hadoop问题锦集(一)-搭建集群环境时的常见问题
- 堆排序 Heap Sort
- phpcms V9静态判断会员登录状态的方法
- java和javax都是Java的API包,java是核心包,javax的x是extension的意思,也就是扩展包。
- IIS发布网站后局域网其他用户不能访问问题(转)
- Step one : 熟悉Unix/Linux Shell 常见命令行 (三)
- mysql具体语句示例
- 哈夫曼树压缩C#算法(huffman)
- MongoDB复制
- gcc8.2安装
- Java基础学习-Path环境变量的配置
- java 网络编程(五)Socket多线程上传文件
- 2.Dubbo2.5.3注册中心和监控中心部署
热门文章
- java实时监听日志写入kafka
- PHP.36-TP框架商城应用实例-后台12-商品管理-主分类添加、修改、搜索(连表查询)
- STM32无法使用IAR下载程序问题
- The Image Gallery Revisited
- gradle编译很慢解决方法
- 《Cracking the Coding Interview》——第16章:线程与锁——题目3
- 嗯,ACM按照这个一步一步来。
- Centos在VMware虚拟机上的网络配置一记
- 新兵易学,老兵易用----C++(C++11的学习整理---如何减少代码量,加强代码的可读性)
- redhat 安装python3