[0] https://en.cppreference.com/w/cpp/numeric/popcount
[1] https://vaibhavsagar.com/blog/2019/09/08/popcount/
If you need the full implementation spelled out I can do that when I get in from my commute home.
Interesting task I guess really you want to find the first (from right) and move the first set bit left to fill it.
[0] https://en.cppreference.com/w/cpp/numeric/popcount
[1] https://vaibhavsagar.com/blog/2019/09/08/popcount/