32位数的1的数字 [英] number of 1's in 32 bit number
本文介绍了32位数的1的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法,在32位数
中使用1的数字而不使用其间的循环。
可以帮助我,并提供代码或算法
这样做。
提前致谢。
I am lookin for a method to have number of 1's in 32 bit number without using a loop in between. can any body help me and provide me the code or algorithm to do so. Thanks in advance.
推荐答案
参见 Integer.bitCount(int)
。如果你想看看它是如何工作的,你可以参考源代码;许多 Integer
类的位错误例程取自 Hacker's Delight。
See Integer.bitCount(int)
. You can refer to the source code if you want to see how it works; many of the Integer
class's bit twiddling routines are taken from Hacker's Delight.
这篇关于32位数的1的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文