All that and more: https://graphics.stanford.edu/~seander/bithacks.html#CountBi... :)