
Hacker's Delight
by Henry S. Warren Jr. · first published 2002
74% recommend24% neutral2% critical
Why HN recommends it
Collection of bit-twiddling and low-level arithmetic tricks, such as magic-number division, overflow detection, perfect hashing and Montgomery multiplication. Suits performance-minded programmers who enjoy the puzzles.
Summarised by Claude from recommending comments
"This is a collection of small programming tricks that I have come across over many years. Most of them will work only on computers that represent integers in two's-complement form. Although a 32-bit machine is assumed when register length is relevant, most of the tricks are easily adapted to machines with other register sizes." "This book does not deal with large tricks such as sophisticated sorting and compiler optimization techniques. Rather, it deals with small tricks that usually involve individual computer words or instructions, such as counting the number of 1-bits in a word. Such tr
Affiliate links. As an Amazon Associate I earn from qualifying purchases.








Obviously using a dedicated instruction is fastest in normal cases. But if you need to implement popcount or many other bit manipulation algorithms in software, a good book to look at is "Hacker's Delight" by Henry S. Warren, Jr, 2003. "Hacker's Delight' page 65+ discuss "Counting 1-bits" (population counts). There are a lot of software algorithms to do this. One approach is to set each 2-bit field to…
on “The NSA Instruction (2019)” ↗For those who enjoy these kind of problems I highly recommend "Hacker's delight". http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...
on “Low Level Bit Hacks You Absolutely Must Know” ↗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. [1] http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...
on “Low Level Bit Hacks You Must Know” ↗Whenever a discussion on rearranging bits and bytes comes up, I can't help but recommend Hacker's Delight by Henry S. Warren http://amzn.com/0201914654
on “Bit Twiddling Hacks” ↗Also recommend the book: Hacker's Delight http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...
on “The demise of the low level programmer” ↗…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 (http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...).
on “Interviewing at Google, Facebook, Foursquare, Dropbox, Fog Creek, etc” ↗Highly recommend the book "Hacker's Delight" by Henry S. Warren, Jr for more bit hax0ring like this.
on “KestrelHttpServer SuperCharged MemoryPoolIterator” ↗…strict by default and with dependent types designed-in from the start. Also describes techniques for leveraging the type system to construct functions (the type-driven part of the title). Well written. Hacker's Delight by Henry S. Warren Low-level bit twiddling. 'Nuff said.
on “Most tech content is bullshit” ↗For some of the "clever tricks" at higher levels, Hacker's Delight is a great treasure trove - it's not x86-64 specific, as a lot of the tricks are applicable to many CPUs, but it helps understand some of the seemingly bizarre tricks. https://www.amazon.com/Hackers-Delight-2nd-Henry-Warren/dp/0...
on “Ask HN: How did you learn x86-64 assembly?” ↗If you're into this sort of thing and like print books, "Hacker's Delight" by Henry S. Warren, Jr. is great.
on “Bit Twiddling Hacks” ↗If you're interested in this, Hacker's Delight has several hundreds of pages of these tricks. The book picks up from a 1972 MIT memo called HAKMEM. For a database/web guy like me, reading it is just recreational, but that's probably true for most…
on “Unsigned comparisons in AVX2/SSE: a quick note” ↗Hacker's Delight by Henry Warren. Don't get distracted by the name, it's about binary mathematics. Bit twiddling at its finest.
on “Ask HN: Which books do you consider real gems in your field of work/study?” ↗…A Guided Tour Through Alan Turing's Historic Paper on Computability and the Turing Machine by Charles Petzold Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Sussman Hacker's Delight by Henry S. Warren Operating System Concepts by Abraham Silberschatz Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein One (or more) of the Algorithms…
on “Steps to become a good hacker?” ↗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. Link: http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...
on “Bithacks.h - bit hack macros” ↗…well in most of the questions, apart from one set involving heavy binary maths — I pretty much forgot basic binary computation from when I did my undergrad course. Following this, it prompted me to buy "Hacker's Delight" by Henry S. Warren. It's a great read if you're into high-performance algorithms http://amzn.com/0201914654 I can't wait to read the next part!
on “Interviewing programmers: coding test results.” ↗