【发布时间】:2011-04-24 02:19:39
【问题描述】:
我想了解更多关于比特的信息,结果发现了this example。
这段代码如何计算位数? (顺便说一句,我的 C 很生锈)。
unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; v >>= 1)
{
c += v & 1;
}
【问题讨论】:
-
这不是代码审查平台。请在代码审查部分执行此操作。有非常好的和更有效的解决方案来计算其他问题中的位,例如这里:stackoverflow.com/questions/109023/…