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 ...
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
原文摘录
· · · · · ·
-x = ~x + 1 = ~(x - 1)
~x = -x - 1
-(~x) = x + 1
~(-x) = x - 1
x + y = x - (~y) - 1 = (x ^ y) + 2*(x & y) = (x | y) + (x & y) = 2*(x | y) - (x ^ y)
x - y = x + ~y + 1 = (x ^ y) - 2*(~x & y) = (x & ~y) - (~x & y) = 2*(x & ~y) - (x ^ y)
x ^ y = (x | y) - (x & y)
x & ~y = (x | y) - y = x - (x & y)
~(x - y) = y - x - 1 = ~x + y
x 恒等于 y = (x & y) - (x | y) - 1 = (x & y) + ~(x | y)
x | y = (x & ~y) + y
x & y = (~x | y) - ~x (查看原文)
Hacker's delight is a interesting book. The only problem is it skiped many steps and hard to follow. For example, one of the topic is how to cout the number of binary 1s for a unsigned interger. 1. Easy answer start from here unsigned int CountBitOne(uns...
(展开)
4 有用 海马 2015-01-27 09:50:17
有点像加德纳写的数学科普文章,各种计算(偏底层)的奇技淫巧。搞算法优化和编译器的童稚可以看看。
0 有用 潟鷌鮙 2024-08-03 16:08:03 上海
二进制博物馆, 么有做不到, 只有想不到.