没有合适的资源?快使用搜索试试~ 我知道了~
首页《黑客必备2》:经典指南
《黑客的喜悦》第二版(Hacker's Delight 2nd Edition)是一本深受程序员和计算机科学爱好者珍视的图书,它专注于提供深入且实用的计算机编程技巧和算法设计。该书由Henry S. Warren Jr. 编著,以一种轻松而富有洞察力的方式探讨了各种计算机科学中的核心概念和技术,特别关注那些能让开发者在编写高效代码时感到“喜悦”的黑客级技巧。 本书的特色在于其涵盖的主题广泛,包括但不限于数据结构、算法优化、内存管理、性能调优等,这些是每个优秀程序员必备的技能。它强调的是通过精巧的设计和优化,提升程序的运行效率,从而解决实际问题中的性能瓶颈。作者通过实例和深入的分析,帮助读者理解如何利用底层原理来实现高效的编程实践。 在版权方面,书中的某些制造商和销售商名称可能被用作商标,当它们在书中出现时,通常采用大写字母或首字母大写的形式以表明所有权。同时,尽管本书旨在提供准确的信息,但作者和出版社并不承担明示或暗示的保修责任,也不对因使用书中的内容或程序导致的偶然或间接损害负责。 值得注意的是,对于批量购买或定制版本,出版社提供了优惠,这可能包括电子版本,以及针对特定业务需求、培训目标或市场推广策略定制的封面和内容。这意味着,《黑客的喜悦》不仅是技术学习者的参考书,也是企业培训和团队提升编程技能的有效工具。 《黑客的喜悦》第二版是一本实用的编程指南,不仅适合专业程序员作为深入理解和提升技术能力的参考资料,也适合对算法和计算机科学感兴趣的业余爱好者进行自我提升。通过阅读这本书,读者将能领略到高效编程的艺术,体验到“黑客”般的解决问题的乐趣。
资源详情
资源推荐
This page intentionally left blank
xiii
FOREWORD
Foreword from the First Edition
When I first got a summer job at MIT’s Project MAC almost 30 years ago, I was
delighted to be able to work with the DEC PDP-10 computer, which was more fun
to program in assembly language than any other computer, bar none, because of
its rich yet tractable set of instructions for performing bit tests, bit masking, field
manipulation, and operations on integers. Though the PDP-10 has not been manu-
factured for quite some years, there remains a thriving cult of enthusiasts who
keep old PDP-10 hardware running and who run old PDP-10 software—entire
operating systems and their applications—by using personal computers to simu-
late the PDP-10 instruction set. They even write new software; there is now at
least one Web site with pages that are served up by a simulated PDP-10. (Come
on, stop laughing—it’s no sillier than keeping antique cars running.)
I also enjoyed, in that summer of 1972, reading a brand-new MIT research
memo called HAKMEM, a bizarre and eclectic potpourri of technical trivia.
1
The
subject matter ranged from electrical circuits to number theory, but what intrigued
me most was its small catalog of ingenious little programming tricks. Each such
gem would typically describe some plausible yet unusual operation on integers or
bit strings (such as counting the 1-bits in a word) that could easily be programmed
using either a longish fixed sequence of machine instructions or a loop, and then
show how the same thing might be done much more cleverly, using just four or
three or two carefully chosen instructions whose interactions are not at all obvious
until explained or fathomed. For me, devouring these little programming nuggets
was like eating peanuts, or rather bonbons—I just couldn’t stop—and there was a
certain richness to them, a certain intellectual depth, elegance, even poetry.
“Surely,” I thought, “there must be more of these,” and indeed over the years
I collected, and in some cases discovered, a few more. “There ought to be a book
of them.”
I was genuinely thrilled when I saw Hank Warren’s manuscript. He has sys-
tematically collected these little programming tricks, organized them thematically,
and explained them clearly. While some of them may be described in terms of
machine instructions, this is not a book only for assembly language programmers.
The subject matter is basic structural relationships among integers and bit strings
1. Why “HAKMEM”? Short for “hacks memo”; one 36-bit PDP-10 word could hold six 6-bit
characters, so a lot of the names PDP-10 hackers worked with were limited to six characters.
We were used to glancing at a six-character abbreviated name and instantly decoding the
contractions. So naming the memo “HAKMEM” made sense at the time—at least to the
hackers.
xiv FOREWORD
in a computer and efficient techniques for performing useful operations on them.
These techniques are just as useful in the C or Java programming languages as
they are in assembly language.
Many books on algorithms and data structures teach complicated techniques
for sorting and searching, for maintaining hash tables and binary trees, for deal-
ing with records and pointers. They overlook what can be done with very tiny
pieces of data—bits and arrays of bits. It is amazing what can be done with just
binary addition and subtraction and maybe some bitwise operations; the fact that
the carry chain allows a single bit to affect all the bits to its left makes addition a
peculiarly powerful data manipulation operation in ways that are not widely
appreciated.
Yes, there ought to be a book about these techniques. Now it is in your hands,
and it’s terrific. If you write optimizing compilers or high-performance code, you
must read this book. You otherwise might not use this bag of tricks every single
day—but if you find yourself stuck in some situation where you apparently need
to loop over the bits in a word, or to perform some operation on integers and it just
seems harder to code than it ought, or you really need the inner loop of some inte-
ger or bit-fiddly computation to run twice as fast, then this is the place to look. Or
maybe you’ll just find yourself reading it straight through out of sheer pleasure.
Guy L. Steele, Jr.
Burlington, Massachusetts
April 2002
xv
PREFACE
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 reg-
ister 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 environ-
ment, 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 mix-
ture of integer and bit-string operations, and C compilers that produce high-quality
object code are available.
Occasionally, machine language is used, employing 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, because on many computers, branches slow
down instruction fetching and inhibit executing instructions in parallel. Another
problem with branches is that they can 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.
剩余77页未读,继续阅读
MacTouch
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C++标准程序库:权威指南
- Java解惑:奇数判断误区与改进方法
- C++编程必读:20种设计模式详解与实战
- LM3S8962微控制器数据手册
- 51单片机C语言实战教程:从入门到精通
- Spring3.0权威指南:JavaEE6实战
- Win32多线程程序设计详解
- Lucene2.9.1开发全攻略:从环境配置到索引创建
- 内存虚拟硬盘技术:提升电脑速度的秘密武器
- Java操作数据库:保存与显示图片到数据库及页面
- ISO14001:2004环境管理体系要求详解
- ShopExV4.8二次开发详解
- 企业形象与产品推广一站式网站建设技术方案揭秘
- Shopex二次开发:触发器与控制器重定向技术详解
- FPGA开发实战指南:创新设计与进阶技巧
- ShopExV4.8二次开发入门:解决升级问题与功能扩展
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功