Algorithm Explained: Counting set bits in a 32-bit signed integer

Problem statement: Given a 32-bit signed integer, how many set bits are there? Ex: The number 15 has four bits set. In this article I’ll explain how I’d approach this problem. Approach How do I know if a bit is set? A bit can either be 0 or 1. A bit is set if its … Read more Algorithm Explained: Counting set bits in a 32-bit signed integer