|
Brief Decimal/Hexidecimal Tutorial
Decimal Numbers Decimal simply means base ten -- this is the number system you learned when you learned to count on your fingers and toes. Every decimal number can be written as a sum in the following form:
The coefficients an are decimal digits -- 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. The indices n represent integers over which we sum. The large funny looking symbol is an upper case sigma, the Greek capital S, representing sum. It's written this way because n can in fact be negative. We can give a specific range for n. For example, we can demand than n runs from 0 to 10, or -4 to 100, or even -infinity to 4. So all we've done is write in a funky way the fact that a decimal number can be written in the form
where the am are digits 0 through 9. So all we've done is taken a decimal number and written it in a sum. Note that we want the largest and smallest term to have nonzero coefficients. It does us no good to allow ourselves things like 0(100) + 0(10) + 4(1). For examples, 325 would be thought of as 3 hundreds plus 2 tens plus 5 ones. 4.67 would be thought of as 4 ones plus 6 tenths plus 7 one-hundredths. By allowing the sum to run over infinitely negative exponents we can get infinitely repeating decimal numbers, like the decimal expansion of 1/3. If you had any sum of money from $0.00 to $999.99 you could express it in base 10 by thinking about it in terms of how many hundreds, tens, ones, dimes, and cents pieces you would have if you had as many of each as possible. (For example, we wouldn't want to think of $1.00 as 100 cent pieces, but instead, as 1 dollar bill.) This goes along with thinking of those coefficients an as being only between 0 and 9. (Think about it -- 9 is the largest digit less than ten, and we're counting in base 10.) If I haven't lost you yet, read on... If I have, well, it's my fault for doing a poor job explaining this all too hastily at 3am. Hexidecimal Numbers Hexidecimal numbers can be thought of just like decimal numbers above, only now the base number is 16 (hex = 6, dec = 10) instead of only 10. So the funny looking sum thing is now
Now, instead of counting by ones, tens, hundreds, and thousands, we're counting by ones, 16's, 256's, etc. Instead of powers of ten, we are working with powers of 16. Instead of digits 0 through 9, our digits are numbers from 0 up to 16, but not equal to 16. Our system of writing doesn't have digits for numbers over 9 because we only had ten fingers (digits) and this greatly influenced our counting system. (Ever see that episode of Schoolhouse Rock?) In order to give ourselves digits to represent the numbers that we think of as having the decimal values of 10, 11, 12, 13, 14, and 15, we assigned these the values of A, B, C, D, E, and F. So now, in base 16, our digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. So base 16 numbers, or 'hex' numbers, are of the form
where the coefficients am are now base 16 digits -- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, or F. Just as before, we can have finite sums of this form, or infinite sums with some greatest positive integer value for m which is nonzero, and infinitely negative integer values to give us fractional expressions. So now we have numbers like ABCD, and 1, and 24, and 3C. Note that numbers like 1 and 24 do not necessarily have the same decimal value as they do hexidecimal value. (Hence, the whole conversion form has a purpose!) In fact, even though 1 base 10 equals 1 base 16, when we're talking about numbers, that 1 base 10 is like an apple, and the 1 base 16 is like an orange. Now, before giving examples of conversions between the two bases, think about how to count in base 16. If you can teach yourself how to count in base 16, you'll have a better grasp of this whole mess. 1 2 3 4 5 6 7 8 9 A B C D E F ... and what comes after F. We've run out of digits, so we have to move up a notch, and count 16's. After F (ie, 15) ones, what do we have? We have 16 ones, but in base 16, this is TEN. That is to say, 16 base ten equals 10 base 16. So to keep counting... 10 11 12 13 14 15 16 17 18 19 20?? Nope. We don't get to 20 yet. Why not? Because our digits don't run from 0 to 9 now, they run from 0 through F. So we really have 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20. Without counting out the remaining hexidecimal two-digit numbers, what do you think the largest two digit hex number is? It'd be the number with double digits, the greatest digit value base 16 -- FF. And what comes after FF in base 16? When we run out of two digit numbers, we go to three digit numbers. You can use the conversion form to convert back and forth between hexidecimal numbers from 0 to FF and decimal numbers from 0 through what? What is FF when we convert it to base 10? Base Conversion Converting from base 10 to base 16 is fairly straightforward. Just the way we'd think of breaking $567.23 into hundreds, tens, ones, dimes, and cent pieces, we want to break our decimal number into powers of 16. So take the number 200. It has 12 16's (in base 16, we really want to call these tens) in it. So the digit for 12 is going to be the coefficient of 16 in our sum. What's left over? Well 200 - (12 * 16) = 8. So we have 8 "ones" left over. So 200 in base 10 becomes [digit for 12] [digit for 8] in base 16, or C8. Converting from base 16 back to base 10 is even easier -- you just need to remember what the hex digits mean in base 10, and that each place in a base 16 number represents the coefficient of a power of 16. The number DA in base 16 is D tens and A ones, or 13 tens and 10 ones, or 13*16 + 10*1 = 218. Well, that's about all I can think of at this point to explain this, and it's a lot later than 3am by now. If I've totally confused you, let me know and I can try to rewrite this in a more easily understood fashion. Enjoy, and please email me any comments, questions, or suggestions that you might have. |