Hacker's Delight / Edition 1
  • Alternative view 1 of Hacker's Delight / Edition 1
  • Alternative view 2 of Hacker's Delight / Edition 1

Hacker's Delight / Edition 1

4.0 2
by Henry S. Warren
     
 

ISBN-10: 0201914654

ISBN-13: 9780201914658

Pub. Date: 07/28/2002

Publisher: Addison-Wesley

At long last, a collection of shortcuts for the programming trade, organized thematically in one volume!

These are the timesaving techniques relished by computer hackers—those devoted and persistent problem-solvers engrossed in their code who seek elegant and efficient solutions for building better software. The truth is that much of the computer programmer

Overview

At long last, a collection of shortcuts for the programming trade, organized thematically in one volume!

These are the timesaving techniques relished by computer hackers—those devoted and persistent problem-solvers engrossed in their code who seek elegant and efficient solutions for building 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 devices 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 collection useful programming devices the author has collected over the years
  • 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. With the help of Hacker's Delight, you will learn to program at a higher level than is generally taught in schools or training courses, and you will advance substantially more than you would through self-directed study.



Product Details

ISBN-13:
9780201914658
Publisher:
Addison-Wesley
Publication date:
07/28/2002
Edition description:
Older Edition
Pages:
306
Product dimensions:
6.50(w) x 9.37(h) x 0.81(d)

Table of Contents

Preface.
1. Introduction.
Notation.
Instruction Set and Execution Time Model.

2. Basis.
Manipulating Rightmost Bits.
Addition Combined with Logical Operations.
Inequalities among Logical and Arithmetic Expressions.
Absolute Value.
Sign Extension.
Shift Right Signed from Unsigned.
Sign Function.
Three-valued Compare.
Transfer of Sign.
Decoding a “Zero Means 2**n” Field.
Comparison Predicates.
Overflow Detection.
Condition Code Result of Add, Subtract, and Multiply.
Rotate Shifts.
Double-length Add/subtract.
Double-length Shifts.
Multibyte Add, Subtract, Absolute Value.
Doz, Max, Min.
Exchanging Registers.
Alternating among Two or More Values.

3. Power-of-2 Boundaries.
Rounding up/down to a Multiple of a Known Power of 2.
Rounding up/down to the Next Power of 2.
Detecting a Power-of-2 Boundary Crossing.

4. Arithmetic Bounds.
Checking Bounds of Integers.
Propagating Bounds through Adds and Subtracts.
Propagating Bounds through Logical Operations.
Signed Bounds.

5. Counting Bits.
Counting 1-bits.
Parity.
Counting Leading Zeros.
Counting Trailing Zeros.

6. Searching Words.
Find First 0-byte.
Find First String of 1-bits of a Given Length.

7. Rearranging Bits and Bytes.
Reversing Bits and Bytes.
Shuffling Bits.
Transposing a Bit Matrix.
Compress, or Generalized Extract.
General Permutations, Sheep and Goats Operation.
Rearrangements and Index Transformations.

8. Multiplication.
Multiword Multiplication.
High-order Half of 64-bit Product.
High-order Product Signed from/to Unsigned.
Multiplication by Constants.

9. Integer Division.
Preliminaries.
Multiword Division.
Unsigned Short Division from Signed Division.
Unsigned Long Division.

10. Integer Division by Constants.
Signed Division by a Known Power of 2.
Signed Remainder from Division by a Known Power of 2.
Signed Division and Remainder by Non-powers of 2.
Signed Division by Divisors >= 2.
Signed Division by Divisors <= -2.
Incorporation into a compiler.
Miscellaneous Topics.
Unsigned Division.
Unsigned Division by Divisors >= 1.
Incorporation into a Compiler (unsigned).
Miscellaneous Topics (unsigned).
Applicability to Nodulus and floor division.
Similar methods.
Sample Magic Numbers.
Exact Division by constants.
Test for Zero Remainder after Division by a Bonstant.

11. Some Elementary Functions.
Integer Square Root.
Integer Cube Root.
Integer Exponentiation.
Integer Logarithm.

12. Unusual Bases for Number Systems.
Base -2.
Base -1 + i.
Other Bases.
What is the Most Efficient Base?

13. Gray Code.
Gray Code.
Incrementing a Gray Coded Integer.
Negabinary Gray Code.
Brief History and Applications.

14. Hilbert's Curve.
A Recursive Algorithm for Generating the Hilbert Curve.
Coordinates from Distance along the Hilbert Curve.
Distance from Coordinates on the Hilbert Curve.
Incrementing the Coordinates on the Hilbert Curve.
Non-recursive Generating Algorithms.
Other Space-filling Curves.
Applications.

15. Floating-Point.
IEEE Format.
Comparing Floating-point Numbers Using Integer Operations.
The Distribution of Leading Digits.
Table of Miscellaneous Values.

16. Formulas for Primes.
Introduction.
Willans's Formulas.
Wormell's Formula.
Formulas for Other Difficult Functions.

Appendix A. Arithmetic Tables for a Four-Bit Machine.
Appendix B. Newton's Method.
References.
Index.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >

Hacker's Delight 4 out of 5 based on 0 ratings. 2 reviews.
Guest More than 1 year ago
At first sight, the book seemed a bit short for $40. But there is quite a bit of information packed in there, and it's certainly much easier to comprehend than picking up one of Knuth's books for the first time. With that said, this really is a book for computer engineers, i.e. people who really like to know what's going on at the bit level. The bit manipulation examples are given in pseudo-assembly, which is very applicable. I can't give 5 stars because of the niche target audience, but it is a very concise, interesting read.
Anonymous More than 1 year ago