Write a function to count the number of set bits in a 32-bit integer. How can you optimize this using bitwise operations?