本文介绍了多少1秒中的n位整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是有趣的问题,我今天碰见:什么是计算在n位整数中1的个数最快的方法?是否有可能击败O(N)?
An interesting problem I ran into today: what is the fastest way to count the number of 1s in an n-bit integer? Is it possible to beat O(n)?
例如:
42 = 0b101010 => 3 ones 512 = 0b1000000000 => 1 one显然,天真的算法是简单地算。但是,有没有什么技巧,以加快步伐?
Clearly, the naive algorithm is to simply count. But, are there any tricks to speed it up?
(这仅仅是一个学术问题;还有通过实施这样的战略没有预期的性能增益)
(This is merely an academic question; there is no expected performance gain by implementing such a strategy.)
推荐答案请参阅神话般位操作黑客的文章
更多推荐
多少1秒中的n位整数?
发布评论