Skip to content
HomeVideosBooks
AllTopicsTrends
BlogsPodcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    Cover of Hacker's Delight

    Hacker's Delight

    Henry S. Warren Jr. · 2002

    "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 tricks often use a mixture of arithmetic and logical instructions." -- From the preface.

    ProgrammingComputer Science
    Open LibraryAmazon
    Stats for nerds
    105recommend
    169mentions
    142people
    2008–2026years
    70% recommend28% neutral2% critical

    Mentions per year

    2008201020122014201620182020202220242026

    What Hacker News says

    1. globular-toastJun 2026
      Anyone interested in branch-free code might like the book Hacker's Delight. Lots of examples of stuff like this in there.
      thread
    2. varispeedMar 2026
      If you are interested in such "tricks", you should check out the classic Hacker's Delight by Henry Warren
      thread
    3. bkallusDec 2025
      I hope he ends up covering integer division by constants. The chapter on this in Hacker's Delight is really good but a little dense for casual readers.
      thread
    4. eschatonOct 2025
      There’s an explanation of how to implement a perfect hash generator in “Hacker’s Delight” that you can read to take a known set of keys and produce a consistent perfect hash at runtime.

      It’s a very worthwhile thing to keep in your back pocket if you’re going to deal with hashes whose keys are 100% knowable at runtime but not before.

      thread
    5. explodingwaffleOct 2024
      that page + the book Hacker's Delight are a big part of the reason I am so convinced of this :)

      If compilers/languages/standard libraries provided these bit permutations, and it was just something ~everyone had learned, it would be a lot easier to work with bits without needing to come up with the bitwise ops (or use that generator). In addition it would probably make better use of the hardware: sure, people like to pretend that we’re still programming C for PDP11, but modern hardware supports more operations than C has operators for (RISC-V B extension and co have the right idea <3)

      Modern compilers are probably pretty good? but I doubt they are perfect at turning code like that in OP into the best instructions. It is probably a bit late for C/C++ though. maaaybe possible to get it into LLVM and Rust.

      thread
    6. globular-toastJul 2024
      Funny, I did this myself 10 years ago. Shit, it's been that long..?

      For my undergrad project I wrote a computer algebra system to do symbolic integration. The supervisor was a hardcore, old school C guy, so naturally I was going to just use C and no libraries. He told me I'd need bignums first, so I got to work (this is because many algorithms like polynomial GCD create massive numbers as they go, even if the inputs and final outputs are generally very small).

      I just couldn't figure out how to do better than the largest power of 10 per digit at the time. Working with non base 10 arithmetic was a mind fuck for me at the time. So I did it with digits holding 10^9 and the classical algorithms from Knuth. Division is the hardest!

      At some point I discovered the GNU multiple precision library (GMP) and made my program work with that instead of mine. I was shocked at how much faster GMP was! I finished my project with my own code, but I knew I had to come back to do it better.

      The breakthrough came when I got a copy of Hacker's Delight. It has stuff like how to detect overflow after it's happened (in C). Something twigged and then I just understood how to fill each word completely rather than use a power of 10. I don't know what confused me before.

      But, of course, the real way to do it is to use assembly. You can't get close to high performance in C alone. In assembly you get the overflow bit. It's actually easier in a way! So you write tiny platform specific bits for the digits and build on that in C. My add and subtract were then as fast as GMP. I lost interest when it came to implement faster multiplication algorithms.

      Code in case anyone is interested: https://github.com/georgek/bignums

      thread

    Related

    Cover of The art of computer programming
    2007–2026

    The art of computer programming

    Donald Knuth
    336 recommend · 1,799
    Cover of Hackers
    2007–2026

    Hackers

    Steven Levy
    130 recommend · 236
    Cover of The C Programming Language
    2007–2026

    The C Programming Language

    Brian W. Kernighan
    246 recommend · 604
    Cover of Code
    2008–2026

    Code

    Charles Petzold
    243 recommend · 385
    Cover of The  (new) turing omnibus
    2008–2025

    The (new) turing omnibus

    A.K. Dewdney
    32 recommend · 42
    Cover of Computer Lib/Dream Machines
    2009–2026

    Computer Lib/Dream Machines

    Ted Nelson
    37 recommend · 100
    Cover of The Art of Computer Programming, Volume 2
    2019–2026

    The Art of Computer Programming, Volume 2

    Donald Knuth
    recommend · 5
    1
    Cover of Code Complete
    2007–2026

    Code Complete

    Steve McConnell
    393 recommend · 894