Appendix: Fast Shortcuts for Computing 2N

There are 10 kinds of people in this world: those who understand binary math and those who do not. Many of us live in a binary world despite our base ten arithmetic system. Often we need to convert a 2N notation to its decimal equivalent. Quick, what is the maximum addressable file size given a 32-bit number system? Well, that is 232, and with a little calculator math, we come up with 4,294,967,296 elements, or approximately 4.3 billion. Is there a faster way to calculate the value? If we apply a few tricks, we can quickly approximate the value to within 7.5 percent worst case. This is good enough for many practical uses.

The basic idea is to split the exponent (N) into two parts n1 and n2, such that n1 + n2 = N. Let n1 equal the tens value of N. So if N = 24, then n1 = 20 and n2 = 4. Now the trick for speedy computation is to approximate the value of 2n1 as a round number. We can do this because 210 = 1,024 and 220 = 1,048,576 for example. So let us approximate 210 to be 1,000 and 220 to be 1,000,000 (1 million, or 106) and 230 to be 1 billion. The max error is only 7.5 percent and often less.

To compute 224, we set n + 1 = 20 and n + 2 = 4. The approximated value is 106 times 24, which is 16 million using 2N = 2n1 * 2n2 where 2n1 = 1 million for this example. The exact value is 16,777,216, so our approximation is within 5 percent. Of course the 2n2 values should be exact, but there are only nine of them to memorize. Most of us likely already know these values (2, 4, 8, 16, 32, 64, 128, 256, 512), especially if we smiled after reading the first sentence of this appendix. Table A.1 shows some other examples. Happy approximating!

image

For this table, K = 103, M = 106, and B = 109.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.57.93