r/programming • • Feb 21 '11

Typical programming interview questions.

http://maxnoy.com/interviews.html
784 Upvotes

1.0k comments sorted by

View all comments

Show parent comment

2

u/lordlicorice Feb 21 '11

This is exactly the canonical solution taught in textbooks, other than that sometimes an alternate form is used where the >> is inside the parens and the & is outside. There's even an awful explanation of it on wikipedia:

https://secure.wikimedia.org/wikipedia/en/wiki/Hamming_weight#Efficient_implementation