Article Written for Computer Club
How Computers Do Math by Don Grim
If you tell yourself "I wish I could do math like a computer", be careful for what you wish for and think again. Granted, a computer does math quickly but we wouldn't want to go through its particular process. A computer converts decimal numbers (0 through 9 digits) to binary numbers (0 and 1 digits). After the computer performs math calculations, it converts the binary numbers back to decimal numbers for our benefit. People would rather see decimal numbers than binary numbers since they have less digits and more meaning. As an example, the decimal number 57 has more meaning to us than its equivalent binary representation of 111001. So why do computers insist on using binary numbers? By using digits of just 0 and 1, the computer breaks down its work to simple On (1) and Off (0) switches enabling the speediest of calculations so that we don't wait as long for the processing.
A decimal number consists of multiples of 10 where a binary number consists of multiples of 2. Here's an example using the decimal number 57 and its binary equivalent:
000057 = 0 x 10^5 + 0 x 10^4 + 0 x 10^3 + 0 x 10^2 + 5 x 10^1 + 7 x 10^0
111001 = 1 x 2^5 + 1 x 2^4 + 1 x 2^3 + 0 x 2^2 + 0 x 2^1 + 1 x 2^0
Here is an example of how we would multiply 57 times 35 manually (remember your times table?):
57
x 35
---
285
171
----
1995
Here is how the computer does the same calculation which is more drawn out but quicker (for the computer):
convert 57 to a binary 111001
convert 35 to a binary 100011
111001
x 100011
------
111001
111001
111001
-----------
11111001011
convert 11111001011 to a decimal 1995
The original Pentium computer has trouble with certain math calculations. Pentium owners can contact Intel to get a free replacement chip that fixes the problem. Some binary numbers cause problems on the Pentium computer especially numbers with a long string of identical digits. The following calculation produces an answer of 256 on a Pentium computer where the correct answer is zero:
4195835 - ( (4195835 / 3145727) x 3145727 )
The binary representation of 4195835 is 10000000000010111111011 (many zeros).
The binary representation of 3145727 is 1011111111111111111111 (many ones).
So, if we could ask a computer about Math, it would probably answer "It's just a bunch of zeros and ones to me".
Article Written for Computer Club
Basic Bits by Don Grim
Most hand-held calculators have a limit of 8 digits so if you multiply 99999999 times 99999999, you get a result of 9.99999 times 10^15 (scientific notation) which doesn't give too much meaning. In my pursuit to find a more accurate and meaningful solution for numbers with high digits, I turned to the trusty computer. However, the computer is limited to 16 digits. So, instead of giving up, I decided to "force" the computer to give me the results.
Though a computer limits the number of digits for a numerical variable (like A), it does not limit the number of characters for a string variable (like A$). Therefore, I set up the following program that inputs numbers as string variables (lines 40 & 50) so that I could input numbers with a lot of digits:
Armed with the above program, high digit multiplication can be accomplished. First, I type GWBASIC HDMULT, and then I input 99999999 and 99999999 as the first and second numbers. Then the computer displays the correct accurate product of the two numbers which is 9999999800000001 (no more scientific notation).
The program works by inputting the numbers as string variables for unlimited digits (lines 40 & 50). In lines 60 through 170, the digits are reversed for easier multiplication and it excludes any characters that are not 0 through 9 (outside ASCII codes 48 through 57). In lines 180 through 310, the two numbers are multiplied in the same process as if you were multiplying by hand (multiplying two digits at a time in line 200). Lines 320 through 370 chop off unneeded leading zeros out of the resulting product.
The program is not only useful for accuracy but it helps with small numbers as well as large numbers. As an example, since we know that 99999999 times 99999999 equals 9999999800000001, we also know that 0.99999999 times 0.99999999 equals 0.9999999800000001.
You can also find some interesting patterns by multiplying large numbers. Some samples are:
It makes you wonder what limits a computer has when it can be pushed to perform past its normal limits.
Article Written for Computer Club
Computers and Statistics by Don Grim
Computers and Statistics go together like peanut butter and jelly. Computers make it easier to calculate statistics especially when factorials (!) and powers (^) are used in the calculations. You'll hear it said that computers don't lie and statistics don't lie. As long as the input is correct, the output is correct. However, even if the output is correct, it is hard to believe sometimes.