4 ms·
Bit Twiddling Hacks
- jwilliams 18y agoThe http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWo... hack is reminiscent of the strlen discussion the other day: http://news.ycombinator.com/item?id=510326 http://news.ycombinator.com/item?id=510326
- nixme 18y agoAh... 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#CountBitsSetKernighan http://graphics.stanford.edu/~seander/bithacks.html#CountBit...
- henning 18y agoThese are good for showing off to other programmers and ensuring your job security/future contracts at your present place of work.
- sketerpot 18y agoNot if you comment properly. Don't worry, these are safe to use!
- kqr2 18y agoAlso check out Hacker's Delight : http://www.hackersdelight.org/ http://www.hackersdelight.org/ http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201914654/ http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...
- critic 18y agoIf the number of CPU cores increases significantly, with the individual cores getting much simpler, I wonder if bit twiddling will be back.