Hacker's Delight
In Hacker’s Delight, Second Edition, Hank Warren once again compiles an irresistible collection of programming hacks: timesaving techniques, algorithms, and tricks that help programmers build more elegant and efficient software, while also gaining deeper insights into their craft. Warren’s hacks are eminently practical, but they’re also intrinsically interesting, and sometimes unexpected, much like the solution to a great puzzle. They are, in a word, a delight to any programmer who is excited by the opportunity to improve.
Extensive additions in this edition include
- A new chapter on cyclic redundancy checking (CRC), including routines for the commonly used CRC-32 code
- A new chapter on error correcting codes (ECC), including routines for the Hamming code
- More coverage of integer division by constants, including methods using only shifts and adds
- Computing remainders without computing a quotient
- More coverage of population count and counting leading zeros
- Array population count
- New algorithms for compress and expand
- An LRU algorithm
- Floating-point to/from integer conversions
- Approximate floating-point reciprocal square root routine
- A gallery of graphs of discrete functions
- Now with exercises and answers
Why Read This Book
You will learn a concentrated toolbox of bit-level algorithms, integer tricks, and elegant low-level techniques that make code smaller, faster, and easier to reason about — especially in constrained or performance-critical systems. The book distills often-surprising solutions (with proofs and worked examples) so you can apply them directly to firmware, embedded Linux, and systems code.
Who Will Benefit
Experienced firmware and systems engineers, embedded developers, and performance-minded C/assembly programmers seeking compact, proven bit-twiddling techniques and low-level algorithmic tricks.
Level: Advanced — Prerequisites: Comfortable programming in C or a C-like language, familiarity with binary and two's-complement integer arithmetic, and basic knowledge of assembly and computer architecture.
Key Takeaways
- Apply bitwise and arithmetic hacks to optimize speed and code size in embedded firmware.
- Implement efficient population counts, parity, bit-reversals, and other bit-manipulation primitives.
- Design and implement CRCs and other error-detection routines using table-driven and bit-level methods.
- Optimize integer division and multiplication (including multiply-by-constant and fixed-point tricks).
- Implement fast PRNGs, hash functions, and low-level utilities suitable for constrained processors.
- Translate algorithmic ideas into portable C or hand-optimized assembly for common embedded ISAs.
Topics Covered
- Introduction and conventions
- Basic bitwise tricks and idioms
- Two's-complement arithmetic and signed tricks
- Integer arithmetic: multiply, divide, and shifts
- Population count, parity, and bit scanning
- Bit permutations, reversal, and packing
- Tables and table-driven algorithms
- Cyclic redundancy checks (CRCs) and error detection
- Random number generation and hashing
- Floating-point tricks and conversions
- Sorting, selection, and small-data algorithms
- Appendices: reference tables, proofs, and implementation notes
Languages, Platforms & Tools
How It Compares
Covers the same practical territory as the online 'Bit Twiddling Hacks' but with formal explanations, proofs, and broader coverage (including CRCs); it's more applied and compact than Knuth's TAOCP while far more hands-on for practitioners.













