相关疑难解决方法(0)

用于找到大于或等于给定值的2的最小幂的算法

我需要找到大于或等于给定值的2的最小幂.到目前为止,我有这个:

int value = 3221; // 3221 is just an example, could be any number
int result = 1;

while (result < value) result <<= 1;
Run Code Online (Sandbox Code Playgroud)

它工作正常,但感觉有点幼稚.这个问题有更好的算法吗?

编辑.有一些很好的Assembler建议,所以我将这些标签添加到问题中.

c++ algorithm assembly

48
推荐指数
7
解决办法
4万
查看次数

标签 统计

algorithm ×1

assembly ×1

c++ ×1