Difference between revisions of "Base numbers/Conversion"
(→Examples) |
(→Examples) |
||
Line 70: | Line 70: | ||
2. Convert the hexadecimal number 0xA7 into decimal. | 2. Convert the hexadecimal number 0xA7 into decimal. | ||
− | Since A means ten and the A is in the "16s place," we have <math> | + | Since A means ten and the A is in the "16s place," we have 0xA7<math> = 10 \times 16 + 7 = 167</math> |
+ | |||
3. Convert 700 into hexadecimal. | 3. Convert 700 into hexadecimal. | ||
<math>16^2 = 256</math>, so 700 will require three digits. | <math>16^2 = 256</math>, so 700 will require three digits. | ||
+ | Using Method 1 above, we want to solve: | ||
+ | <center><math> 700 = a_0 + 16a_1 + 256a_2</math></center> | ||
+ | |||
+ | <math>\frac{700}{256} = 2 </math> remainder 188, so <math> a_2 = 2</math> | ||
+ | <center><math> 188 = a_0 + 16a_1</math></center> | ||
+ | <math>\frac{188}{16} = 11</math> remainder 12, so <math> a_1 = 11</math> and <math>a0=12</math> | ||
+ | We have | ||
+ | <center><math> 700 = 12 + 16 \times 11 + 256 \times 2</math></center> | ||
+ | Using standard hexadecimal notation, we can write | ||
+ | <center>'''700 = 0x2BC'''</center> | ||
+ | |||
4. Convert 0xF7B9 into binary. (hint: You can do this directly without first converting into decimal) | 4. Convert 0xF7B9 into binary. (hint: You can do this directly without first converting into decimal) |
Revision as of 09:19, 18 November 2006
Contents
[hide]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. 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 do we 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 . We may continue to divide beyond this point, of course, but it is clear that we 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, .
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 . 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.
Binary and Hexadecimal
Two of the most common number bases are binary (base 2) and hexadecimal (base 16). Both of these are used in computer science. A binary number consists entirely of 0s and 1s. Each binary digit is called a bit. A base 16 number requires additional symbols after 9 since any positive integer less than 16 is a single digit. The standard notation is to use the letters a=10,b=11,c=12,d=13,e=14,f=15. In order to indicate that a number is written in hexadecimal, the prefix 0x is used. For instance, 0x95 is the same as and is equivalent to
Examples
1. Convert the binary number 1111 1110 to decimal. (A space is often inserted every 4 digits to improve readability of binary numbers. A group of 4 digits (bits) is called a nible and a group of 8 bits is called a byte)
We could simply add all of the digit values: . But, there is a much shorter way. Note that in base 10, 99 = 102 - 1 and 999 = 103 - 1. Similarly, in base 2, 11 = 22 - 1, 111 = 23 - 1, and so on. Therefore, 1111 1111 = 28 -1 = 255. The number we are trying to convert is one less, so it must be 254.
2. Convert the hexadecimal number 0xA7 into decimal.
Since A means ten and the A is in the "16s place," we have 0xA7
3. Convert 700 into hexadecimal.
, so 700 will require three digits.
Using Method 1 above, we want to solve:
remainder 188, so
remainder 12, so and We have
Using standard hexadecimal notation, we can write
4. Convert 0xF7B9 into binary. (hint: You can do this directly without first converting into decimal)
Resources
Books
- The AoPS Introduction to Number Theory by Mathew Crawford.
- The Art of Problem Solving Volume 1: the BASICS, pgs. 52-54 by Sandor Lehoczky and Richard Rusczyk.
Classes