Found in 12 comments on Hacker News
mjcohen · 2019-02-08 · Original thread
"Hacker's Delight" ( has a whole chapter on this. So, yes, it is well known.
fjarlq · 2013-07-30 · Original thread
A great companion to this sort of thing is the book Hacker's Delight by Henry S. Warren, Jr:

BlackJack · 2012-05-22 · Original thread
I'm a rising junior at Yale, and I know Sean well and we both took systems programming together. We definitely covered bit manipulation and bit tricks, as well as number representation and lots of other stuff.

Sean's an incredibly bright guy but he's more interested in building world-changing apps and web dev. as opposed to low-level systems programming. There are other classes here where you have to code in assembly and do all sorts of bit manipulation (OS's comes to mind). The core CS sequence in our school is also in C, which differs notably from other places that use Python, Java, etc.

For anyone who wants to learn more about bit manipulation, Henry Warren's "Hacker's Delight" is a terrific book (

Erwin · 2012-03-04 · Original thread
If you like this sort of bit-level puzzles, this is a nice book: -- probably the only book at such a low level I remember buying in many years.
kqr2 · 2011-08-07 · Original thread
Also recommend the book: Hacker's Delight

"Hacker's Delight" ( is also a good source for these, as well as other techniques.
If you're interested in reading about more of these, and how they work I'd highly suggest reading the book Hacker's Delight by Henry S. Warren[1]. I know that I've used more than a few of the tricks in my day-to-day work.


drallison · 2010-02-17 · Original thread
The article is not available at the moment so I am flying a bit blind here.

H. Warren, Hackers Delight has a nice discussion of this problem. One of my favorite books, but I like to do code generators.

azanar · 2009-09-03 · Original thread
Another great resource for tidbits like this is _Hacker's Delight_, by Henry S. Warren, Jr. It covers a number of other tricks outside of bit twiddling, as well. Worth checking out for anyone who finds this sort of stuff fascinating.


old-gregg · 2009-06-30 · Original thread
For those who enjoy these kind of problems I highly recommend "Hacker's delight".

axod · 2009-03-10 · Original thread
Clever stuff. If you're interested in such things, best book I've seen is "Hackers Delight"

Author covers really clever techniques to count bits, count non zero bytes like this etc etc. Bit manipulation at its best.

Fresh book recommendations delivered straight to your inbox every Thursday.