多少1秒中的n位整数?

编程入门 行业动态 更新时间:2024-10-24 12:26:11
本文介绍了多少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位整数?

本文发布于:2023-11-30 01:32:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!