

Bit Twiddling Hacks  - mroman
http://graphics.stanford.edu/~seander/bithacks.html

======
kqr2
Also check out _Hacker's Delight_ :

<http://www.hackersdelight.org/>

[http://www.amazon.com/Hackers-Delight-Henry-S-
Warren/dp/0201...](http://www.amazon.com/Hackers-Delight-Henry-S-
Warren/dp/0201914654/)

------
nixme
Ah... I have some good memories of adapting some of these for microcontrollers
while still in school.

My favorite is Kernighan's method for counting set bits. It's as short and
clean as the naive method and not immediately obvious:
[http://graphics.stanford.edu/~seander/bithacks.html#CountBit...](http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan)

------
jwilliams
The
[http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWo...](http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord)
hack is reminiscent of the strlen discussion the other day:
<http://news.ycombinator.com/item?id=510326>

------
critic
If the number of CPU cores increases significantly, with the individual cores
getting much simpler, I wonder if bit twiddling will be back.

------
henning
These are good for showing off to other programmers and ensuring your job
security/future contracts at your present place of work.

~~~
sketerpot
Not if you comment properly. Don't worry, these are safe to use!

