Best algorithm to count the number of set bits in a 32-bit integer?

Posted by Matt Howells on Stack Overflow See other posts from Stack Overflow or by Matt Howells
Published on 2008-09-20T19:04:38Z Indexed on 2010/04/13 15:52 UTC
Read the original article Hit count: 300

8 bits representing the number 7 look like this:

00000111

Three bits are set. What is the best algorithm to determine the number of set bits in a 32-bit integer?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about bit-manipulation