I was playing with code for a decoder today and had to find an algorithm to calculate all bits set in the short integer and find also first bit set (lowest) and last bit set (highest). Certainly simple task with these sites to start with.
Bit Twiddling Hacks [graphics.stanford.edu]
There are posted many different algorithms which you can choose which suits you.
Aggregate Magic Algorithms [aggregate.org/MAGIC/]
Less, but also useful.
KEIL - Counting set bits in byte [keil.com/support]
Nothing new to mention but it's short in context.
More sources [aggregate.org/MAGIC]
More links for reading found on aggregate magic algorithms.