Wednesday, August 29, 2007

Bits manipulation

I came across 2 nice articles about bit manipulations. Both has techniques of how to count set/off bits in an integer. What makes them interesting is it describes how to do it in constant time and memory. It has nice explanations in lined.
http://infolab.stanford.edu/~manku/bitcount/bitcount.html
http://tekpool.wordpress.com/tag/bit-fiddling/
last link also has discussion of swapping 2 numbers without using temporary space, using X-Or operator, mentions an interesting case if 2 numbers are at same memory location.

No comments: