That’s the Hamming weight problem, a.k.a. population count. The link mentions efficient implementations. Quoting:
With unlimited memory, we could simply create a large lookup table of the Hamming weight of every 64 bit integer
More Related Contents:
- How to count the number of set bits in a 32-bit integer?
- Generate all binary strings of length n with k bits set
- Why do we use Base64?
- Count the number of set bits in a 32-bit integer
- Efficient way to add element to sorted datastructure [closed]
- Algorithm to return all combinations of k elements from n
- Graph Algorithm To Find All Connections Between Two Arbitrary Vertices
- How do you detect Credit card type based on number?
- How does finding a cycle start node in a cycle linked list work?
- Millions of 3D points: How to find the 10 of them closest to a given point?
- Algorithm to randomly generate an aesthetically-pleasing color palette [closed]
- How to efficiently build a tree from a flat structure?
- What would cause an algorithm to have O(log log n) complexity?
- What is a good Hash Function?
- Check if one integer is an integer power of another
- How best to sum up lots of floating point numbers?
- Algorithm to tell if two arrays have identical members
- Quicksort vs heapsort
- Find 2 numbers in an unsorted array equal to a given sum
- Algorithm to find the most common substrings in a string
- Simplest way to get the top n elements of a Scala Iterable
- Find cycle of shortest length in a directed graph with positive weights
- Random points inside a parallelogram
- How is 2D bin packing achieved programmatically?
- Optimizing Conway’s ‘Game of Life’
- How do I find the median of numbers in linear time using heaps?
- What are probabilistic data structures?
- How to find the number of different shortest paths between two vertices, in directed graph and with linear-time?
- Finding rectangles in a 2d block grid
- Connected Component Labeling – Implementation