This is the solution to problem 9 on the hard interview questions node. If you have not read the question, the following will make no sense to you:

(b & (b-1)) == 0

Visit the counting 1 bits node for a good explanation of why this works.