(b & (b-1)) == 0
Visit the counting 1 bits node for a good explanation of why this works.
printable version
link view
Everything2 Help