Difference between revisions of "Base numbers"
(added an alternative version of method 1) |
(added octal) |
||
Line 64: | Line 64: | ||
=== Binary === | === Binary === | ||
− | Binary is base 2. It's a favorite among computer programmers. | + | Binary is base 2. It's a favorite among computer programmers. It has just two digits: <math>0</math> and <math>1</math>. |
+ | |||
+ | ===Octal === | ||
+ | Octal is base 8. It was also quite liked by programmers because the octal representation of numbers is 3 times shorter than the binary one and the conversion from octal to binary and back is very easy (can you guess why?). Besides, 8 is quite close to 10 and less than 10, so to learn doing addition and multiplication in base 8 is not very hard: you can basically count in base 10 with partial conversions to base 8 on the way. Let's, say, multiply <math>12345_8</math> by <math>7_8</math>. <math>5\cdot 7=35_{10}=43_8</math> (to get the last result, just divide <math>35</math> by <math>8</math> with remainder. As usual, we write the last digit <math>3</math> down and keep <math>4</math> in mind. Now, <math>4\cdot 7+4=32_{10}=40_8</math>, so we write down <math>0</math> getting <math>03</math> and keep <math>4</math> in mind. | ||
+ | And so on. The time needed to get the answer <math>111103_8</math> only marginally exceeds the time of decimal multiplication (if you are good in division by 8 with remainder, of course). | ||
=== Decimal === | === Decimal === | ||
Line 70: | Line 74: | ||
=== Hexadecimal === | === Hexadecimal === | ||
− | Hexadecimal is base 16. The digits in hexadecimal are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. One of its common uses is for color charts. | + | Hexadecimal is base 16. The digits in hexadecimal are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. One of its common uses is for color charts. Hexadecimal numbers are also used by programmers in the same way as octal numbers, but to learn to count in hexadecimal is harder than in octal. |
== History == | == History == | ||
Base-10 is an apparently obvious counting system because people have 10 fingers. Historically, different societies utilized other systems. The Babylonians and some Native American cultures (Incas?) are known to have used base-60; this is why we say there are 360 degrees in a circle and (fact check on this coming one) why we count 60 minutes in an hour and 60 seconds in a minute. The Roman system (internal link w/explanation?), which didn't have any base system at all, but rather used certain letters to represent certain values (e.g. I=1, V=5, X=10, L=50, C=100, D=500, M=1000). Imagine how difficult it would be to multiply LXV by MDII! That's why the introduction of the '''Arabic numeral system''', base-10, revolutionized math and science in Europe. | Base-10 is an apparently obvious counting system because people have 10 fingers. Historically, different societies utilized other systems. The Babylonians and some Native American cultures (Incas?) are known to have used base-60; this is why we say there are 360 degrees in a circle and (fact check on this coming one) why we count 60 minutes in an hour and 60 seconds in a minute. The Roman system (internal link w/explanation?), which didn't have any base system at all, but rather used certain letters to represent certain values (e.g. I=1, V=5, X=10, L=50, C=100, D=500, M=1000). Imagine how difficult it would be to multiply LXV by MDII! That's why the introduction of the '''Arabic numeral system''', base-10, revolutionized math and science in Europe. |
Revision as of 19:25, 22 June 2006
Contents
Introduction
To understand the notion of base numbers, we look at our own number system. We use the decimal, or base-10, number system. To help explain what this means, consider the number 2746. This number can be rewritten as
Note that each number in 2746 is actually just a placeholder which shows how many of a certain power of 10 there are. So the first digit to the left of the decimal place (recall that the decimal place is to the right of the 6, i.e. 2746.0) tells us that there are six 's, the second digit tells us there are four 's, the third digit tells us there are seven 's, and the fourth digit tells us there are two 's.
Base-10 uses digits 0-9. Usually the base, or radix, of a number is denoted as a subscript written at the right end of the number (e.g. in our example above, , 10 is the radix).
Converting between bases
Converting from base b to base 10
The next natural question is: how do we convert a number from another base into base 10? For example, what does mean? Just like base 10, the first digit to the left of the decimal place tells us how many 's we have, the second tells us how many 's we have, and so forth. Therefore:
From here, we can generalize. Let be an -digit number in base . In our example () and . We convert this to base 10 as follows:
Converting from base 10 to base b
It turns out that converting from base 10 to other bases is far harder for us than converting from other bases to base 10 was. This shouldn't be a suprise though. We work in base 10 all the time so we are naturally less comfortable with other bases. Nonetheless, it is important to understand how to convert from base 10 into other bases.
We'll look at two methods for converting from base 10 to other bases.
Method 1
Let's try converting 1000 base 10 into base 7. Basically, we are trying to find the solution to the equation
where all the are digits from 0 to 6. Obviously, all the from and up are 0 since otherwise they will add in a number greater than 1000 and all the terms in the sum are nonnegative. Then, we wish to find the largest such that does not exceed 1000. Thus since and . This leaves us with
Using similar reasoning we find that leaving us with
We use the same procedure twice more to get that and .
Finally, we have that .
An alternative version of method 1 is to find the "digits" starting with . Note that is just the remainder of division of by . So, to find it, all we need to do is to carry out one division with remainder. We have . How to find now? It turns out that all we need to do is to find the remainder of the division of the quotient by : , so . Now, , so . Finally, , so . One may continue to divide beyond this point, of course, but it is clear that he will just get during each step.
Note that both versions of this method use computations in base
It's often a good idea to double check by converting your answer back into base 10 since this conversion is easier to do. We know that so we can rest assured we got the right answer.
Method 2
We'll exhibit the second method with the same problem used to exhibit the first method.
The second method is just like how we converted from other bases into base 10. To do this, we pretend that our standard number system is base 7. In base 7, however, there is no digit 7. So 7 is actually represented as 10! Also, the multiplication rules we know do not hold. For example, (in base 7). For one, there is no 9 in base 7. Second, we need to go back to the definition of multiplication to fully understand what's happening. Multiplication is a shorthand for repeated addition. So .
So in base 7, we have that 10 (the decimal number 10) is 13. Thus, if we view everything from base 7, we are actually converting to base 10. So, this is just . But remember that we aren't doing this in our regular decimal system, so . Instead, we have to compute as .
This method can be very confusing unless you have a very firm grasp on the notion of number systems.
Common bases
Commonly used bases are 2, 8, 10 (duh!) and 16. The base doesn't necesarily have to be an integer. There are complex, irrational, negative, and many other kinds of bases. The best known one is phinary, which is base phi.
Binary
Binary is base 2. It's a favorite among computer programmers. It has just two digits: and .
Octal
Octal is base 8. It was also quite liked by programmers because the octal representation of numbers is 3 times shorter than the binary one and the conversion from octal to binary and back is very easy (can you guess why?). Besides, 8 is quite close to 10 and less than 10, so to learn doing addition and multiplication in base 8 is not very hard: you can basically count in base 10 with partial conversions to base 8 on the way. Let's, say, multiply by . (to get the last result, just divide by with remainder. As usual, we write the last digit down and keep in mind. Now, , so we write down getting and keep in mind. And so on. The time needed to get the answer only marginally exceeds the time of decimal multiplication (if you are good in division by 8 with remainder, of course).
Decimal
Decimal is base 10. It's the base that everyone knows and loves. Most numbers in the world are written without a specified radix and usually it can just be assumed that they are in base 10. The most commonly used explanation for the origin of base 10 for our number system is the number of fingers we have.
Hexadecimal
Hexadecimal is base 16. The digits in hexadecimal are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. One of its common uses is for color charts. Hexadecimal numbers are also used by programmers in the same way as octal numbers, but to learn to count in hexadecimal is harder than in octal.
History
Base-10 is an apparently obvious counting system because people have 10 fingers. Historically, different societies utilized other systems. The Babylonians and some Native American cultures (Incas?) are known to have used base-60; this is why we say there are 360 degrees in a circle and (fact check on this coming one) why we count 60 minutes in an hour and 60 seconds in a minute. The Roman system (internal link w/explanation?), which didn't have any base system at all, but rather used certain letters to represent certain values (e.g. I=1, V=5, X=10, L=50, C=100, D=500, M=1000). Imagine how difficult it would be to multiply LXV by MDII! That's why the introduction of the Arabic numeral system, base-10, revolutionized math and science in Europe.