- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
As always, this page is indespensable.
https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious
Admin
Bernie's comment shows he doesn't really understand what's going on here. Neither do many of the commenters. Basically the algorithm is doing a binary search over the bits of the input to find the highest 1 with just 5 comparisons. It looks ugly but it's pretty much the most efficient way to implement this function.