Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet, or computer - no Kindle device required.
Read instantly on your browser with Kindle for Web.
Using your mobile phone camera - scan the code below and download the Kindle app.
Follow the author
OK
Hacker's Delight First Edition
- ISBN-100201914654
- ISBN-13978-0201914658
- EditionFirst Edition
- PublisherAddison-Wesley
- Publication dateJanuary 1, 2002
- LanguageEnglish
- Dimensions6.5 x 1 x 9.25 inches
- Print length306 pages
Customers who viewed this item also viewed
Editorial Reviews
From the Back Cover
"This is the first book that promises to tell the deep, dark secrets of computer arithmetic, and it delivers in spades. It contains every trick I knew plus many, many more. A godsend for library developers, compiler writers, and lovers of elegant hacks, it deserves a spot on your shelf right next to Knuth."
--Josh Bloch"When I first saw the title, I figured that the book must be either a cookbook for breaking into computers (unlikely) or some sort of compendium of little programming tricks. It's the latter, but it's thorough, almost encyclopedic, in its coverage."
--Guy SteeleThese are the timesaving techniques relished by computer hackers--those devoted and persistent code developers who seek elegant and efficient ways to build better software. The truth is that much of the computer programmer's job involves a healthy mix of arithmetic and logic. In Hacker's Delight, veteran programmer Hank Warren shares the tricks he has collected from his considerable experience in the worlds of application and system programming. Most of these techniques are eminently practical, but a few are included just because they are interesting and unexpected. The resulting work is an irresistible collection that will help even the most seasoned programmers better their craft.
Topics covered include:
- A broad collection of useful programming tricks
- Small algorithms for common tasks
- Power-of-2 boundaries and bounds checking
- Rearranging bits and bytes
- Integer division and division by constants
- Some elementary functions on integers
- Gray code
- Hilbert's space-filling curve
- And even formulas for prime numbers!
This book is for anyone who wants to create efficient code. Hacker's Delight will help you learn to program at a higher level--well beyond what is generally taught in schools and training courses--and will advance you substantially further than is possible through ordinary self-study alone.
0201914654B06272002
About the Author
Henry S. Warren, Jr., has had a forty-year career with IBM, spanning from the IBM 704 to the PowerPC. He has worked on various military command and control systems and on the SETL project under Jack Schwartz at New York University. Since 1973 he has been with IBM's Research Division, focusing on compilers and computer architectures. Hank currently works on the Blue Gene petaflop computer project. He received his Ph.D. in computer science from the Courant Institute at New York University.
0201914654AB06272002
Excerpt. © Reprinted by permission. All rights reserved.
Caveat Emptor: The cost of software maintenance
increases with the square of the programmer's creativity.First Law of Programmer Creativity, Robert D. Bliss, 1992
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 the 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.
It is assumed throughout that integer overflow interrupts have been masked off, so they cannot occur. C, Fortran, and even Java programs run in this environment, but Pascal and ADA users beware!
The presentation is informal. Proofs are given only when the algorithm is not obvious, and sometimes not even then. The methods use computer arithmetic, "floor" functions, mixtures of arithmetic and logical operations, and so on. Proofs in this domain are often difficult and awkward to express.
To reduce typographical errors and oversights, many of the algorithms have been executed. This is why they are given in a real programming language, even though, like every computer language, it has some ugly features. C is used for the high-level language because it is widely known, it allows the straightforward mixture of integer and bit-string operations, and C compilers that produce high-quality object code are available.
Occasionally, machine language is used. It employs a three-address format, mainly for ease of readability. The assembly language used is that of a fictitious machine that is representative of today's RISC computers.
Branch-free code is favored. This is because on many computers, branches slow down instruction fetching and inhibit executing instructions in parallel. Another problem with branches is that they may inhibit compiler optimizations such as instruction scheduling, commoning, and register allocation. That is, the compiler may be more effective at these optimizations with a program that consists of a few large basic blocks rather than many small ones.
The code sequences also tend to favor small immediate values, comparisons to zero (rather than to some other number), and instruction-level parallelism. Although much of the code would become more concise by using table lookups (from memory), this is not often mentioned. This is because loads are becoming more expensive relative to arithmetic instructions, and the table lookup methods are often not very interesting (although they are often practical). But there are exceptional cases.
Finally, I should mention that the term "hacker" in the title is meant in the original sense of an aficionado of computers--someone who enjoys making computers do new things, or do old things in a new and clever way. The hacker is usually quite good at his craft, but may very well not be a professional computer programmer or designer. The hacker's work may be useful or may be just a game. As an example of the latter, more than one determined hacker has written a program which, when executed, writes out an exact copy of itself1. This is the sense in which we use the term "hacker." If you're looking for tips on how to break into someone else's computer, you won't find them here.H. S. Warren, Jr.
Yorktown, New York
February 2002
1. The shortest such program written in C, known to the present author, is by Vlad Taeerov and Rashit Fakhreyev and is 64 characters in length: main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}
0201914654P08282002
Excerpt. © Reprinted by permission. All rights reserved.
Caveat Emptor: The cost of software maintenance
increases with the square of the programmer's creativity.
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 the 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.
It is assumed throughout that integer overflow interrupts have been masked off, so they cannot occur. C, Fortran, and even Java programs run in this environment, but Pascal and ADA users beware!
The presentation is informal. Proofs are given only when the algorithm is not obvious, and sometimes not even then. The methods use computer arithmetic, "floor" functions, mixtures of arithmetic and logical operations, and so on. Proofs in this domain are often difficult and awkward to express.
To reduce typographical errors and oversights, many of the algorithms have been executed. This is why they are given in a real programming language, even though, like every computer language, it has some ugly features. C is used for the high-level language because it is widely known, it allows the straightforward mixture of integer and bit-string operations, and C compilers that produce high-quality object code are available.
Occasionally, machine language is used. It employs a three-address format, mainly for ease of readability. The assembly language used is that of a fictitious machine that is representative of today's RISC computers.
Branch-free code is favored. This is because on many computers, branches slow down instruction fetching and inhibit executing instructions in parallel. Another problem with branches is that they may inhibit compiler optimizations such as instruction scheduling, commoning, and register allocation. That is, the compiler may be more effective at these optimizations with a program that consists of a few large basic blocks rather than many small ones.
The code sequences also tend to favor small immediate values, comparisons to zero (rather than to some other number), and instruction-level parallelism. Although much of the code would become more concise by using table lookups (from memory), this is not often mentioned. This is because loads are becoming more expensive relative to arithmetic instructions, and the table lookup methods are often not very interesting (although they are often practical). But there are exceptional cases.
Finally, I should mention that the term "hacker" in the title is meant in the original sense of an aficionado of computers--someone who enjoys making computers do new things, or do old things in a new and clever way. The hacker is usually quite good at his craft, but may very well not be a professional computer programmer or designer. The hacker's work may be useful or may be just a game. As an example of the latter, more than one determined hacker has written a program which, when executed, writes out an exact copy of itself1. This is the sense in which we use the term "hacker." If you're looking for tips on how to break into someone else's computer, you won't find them here.
H. S. Warren, Jr.Yorktown, New York
February 2002
1. The shortest such program written in C, known to the present author, is by Vlad Taeerov and Rashit Fakhreyev and is 64 characters in length: main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}
0201914654P08282002
Product details
- Publisher : Addison-Wesley; First Edition (January 1, 2002)
- Language : English
- Hardcover : 306 pages
- ISBN-10 : 0201914654
- ISBN-13 : 978-0201914658
- Item Weight : 1.25 pounds
- Dimensions : 6.5 x 1 x 9.25 inches
- Best Sellers Rank: #641,630 in Books (See Top 100 in Books)
- #166 in Personal Computer Books
- #466 in Computer Hacking
- #670 in Microsoft Programming (Books)
- Customer Reviews:
About the author

There's a short bio on the back cover of Hacker's Delight.
I want to point out here the existence of www.HackersDelight.org. This site will have errata files for the book (second edition) as errors are found. It has C code for the algorithms in the book and many similar algorithms.
Customer reviews
Customer Reviews, including Product Star Ratings help customers to learn more about the product and decide whether it is the right product for them.
To calculate the overall star rating and percentage breakdown by star, we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzed reviews to verify trustworthiness.
Learn more how customers reviews work on AmazonCustomers say
Customers find the book contains a great collection of techniques and tricks for highly efficient numerical operations. They say it explains the tricks very clearly and is exceptional for learning fast implementations of base-2 operations. Readers also describe the content as interesting and a great read.
AI-generated from the text of customer reviews
Customers find the book contains a great collection of techniques and tricks for highly efficient numerical programming. They say it explains the tricks very clearly and is exceptional for learning fast implementations of base-2 operations. Readers also mention the exposition is practical and no deep mathematical skills are required to understand it. In addition, they mention the book has good material on computer arithmetic and is good for a brain teaser.
"...This book is for real hackers. It's a great collection of tricks for performing usually simple operations in an elegant way. What's elegant?..." Read more
"...6 "Counting Bits" and "Searching Words" There is some good material on computer arithmetic including using a radix -2 system, and a chapter on..." Read more
"...This book also *explains* the tricks very clearly. That's why it rocks. Warren doesn't talk to you like a professor, but like a good friend...." Read more
"...The exposition is practical, and no deep mathematical skills are required to understand it...." Read more
Customers find the book great and interesting. They say it provides a different view of bit-wise tricks.
"...This book is fantastic - I kid you not - on the first page of Chapter 2, for example, I discovered at least five or six capriciously clever tricks..." Read more
"Interesting content. Very good to have a different view of bit-wise tricks. Also good for a brain teaser I guess =)" Read more
"...Great read." Read more
-
Top reviews
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
This book is a collection of tricks that show the reader better ways to do things they already know how to do. And it's also a book that can give the reader insight into different approaches and mechanisms for solving problems.
Computer programmers translate their ideas and requirements into any of several computer languages. Those expressions are limited by the language the programmer is using, and maybe even the machine the programmer is targeting. But there is a wide continum of expressions that result in the same -- hopefully correct -- results. Choosing the most efficient, and most elegant, expression to some is "real" hacking.
This book is for real hackers. It's a great collection of tricks for performing usually simple operations in an elegant way. What's elegant? Well, elegant is efficeint. If there's a side-effect of an elegant operation, it turns out that side-effect is probably useful and not simply discarded.
This book catalogs insights into concrete binary math, shortcuts derived from different boolean operators, and even approaches some interesting numerical analysis problems.
If you already know how to write software, and you already know you want to find faster or more efficient ways to check for overflows on integers, divide nubmers, count bits, search for binary patterns, or do other twiddling, then this book is for you.
If the application of such techniques doesn't seem important to you, then this book probably isn't going to be of interest to you.
I recently added a "Conundrums, Puzzles, and Posers" section to the "Programs and Subroutines" page on my DIY Calculator website ([...]) and I've started to build a collection of simple puzzles for people to play with.
One of the first problems I posed was to count the number of ones in the 8-bit accumulator and to present the result as a binary value. I thought I had discovered the best-possible solution, until someone pointed me in the direction of the "Hacker's Delight". (In this context, "Hacker" refers to a hero who is manipulating code; not a nefarious rapscallion who breaks into other people's computer systems.)
I immediately ordered a copy from Amazon, and took delivery just yesterday as I pen these words. This book is fantastic - I kid you not - on the first page of Chapter 2, for example, I discovered at least five or six capriciously clever tricks that blew my solutions out of the water!
I highly recommend this book.
This book also *explains* the tricks very clearly. That's why it rocks. Warren doesn't talk to you like a professor, but like a good friend. He explains stuff, often in plain English, the way we all do when we really want someone to understand what we mean.
He uses some math too, but only when really appropriate, never in a pedantic way or to impress us with his vast knowledge (like a professor would).
This book sports a quick little introduction to RISC assembly, a couple of silly little poems, formulas for prime numbers... how can I explain it?
Top reviews from other countries
Wer aber das letzte aus seiner in C, C++ oder Assembler programmierten Hardware herausholen will oder muß, findet "optimalste" Algorithmen für eine Vielzahl von Grundproblemen. Auch wer sich interessehalber mit Algorithmen auf der Ebene der Bit-Manipulation beschäftigen will, wird in diesem Buch viel Anregendes finden.
Gestaltung und Layout halte ich für gelungen und übersichtlich, der Hardcover-Einband passt zu diesem zeitlosen Referenz- und Nachschlagewerk.

