Base 16Date: 07/07/97 at 13:14:36 From: Cristy White Subject: Addition and subtraction in base 16. Dr.Math, I've been playing a game called RAMA. They have these puzzles where I have to convert symbols to numbers. There are only 16 symbols, 0 through 15. Knowing which symbol represents what number, they give you several symbols telling you to add or subtract. The confusing part is that you have to add and subtract in base 16. How do you add and subtract in base 16? Please help, Cristy White Date: 07/10/97 at 03:30:19 From: Doctor Marko Subject: Re: Addition and subtraction in base 16. Hi Cristy, In order to talk about different bases, we first need to agree on the digits that we shall use in that bases. So for example, in the traditional base 10 system we use 10 digits: 0,1,2,3,4,5,6,7,8, and 9. In base 16 then we must have 16 digits, and to try to simplify things as much as possible, we use lots of base 10 nomenclature. This means, for example, that 0 in base 16 represents the same thing as 0 in base 10; we put this in equation form: 0(16) = 0(10), where the 16 and the 10 in parentheses refer to bases. Similarly, we can say 1(16) = 1(10)... 9(16) = 9(10). But what now? We ran out of our "regular" digits once we reached 9, so we must come up with the other six digits. Traditionally, people have used capital letters A through F, but you can really adopt any system you wish. For consistency, though, I will use the traditional system, which means: A(16) = 10(10), B(16) = 11(10), ..., F(16) = 15(10). The first thing one should know about any numbers in any base is how to convert them to something we know about - base 10. In base 10, the digit left of the decimal point is often called the singles digit, the one left of that is the tens digit, yet more to the left the hundreds digit, and so on. Why these names? Well, I will give you an example: 143(10) has 1 as its hundreds digit, 4 as its tens digit and 3 as its singles digit, which means that 143(10) = 1*100+4*10+3*1, which people write as 1*10^2+4*10^1+3*10^0 for educational purposes. The thing to notice and remember from this little example is that the digits on the left side of the number carry more weight (i.e. are worth more) than those on the right side - you'd rather have $100 then $10, right? :) Also, you should learn that the relative strength goes as the appropriate power of the base that you are dealing with. In general, if the base is m, the digit to the left of the decimal place has m^0(=1) weight, the next one over to the left has m^1(=m) weight, and so on. It is important to notice that this whole scheme works together with our original definition of the digits, for example, just as we defined it: A(16) = 10*16^0 = 10(10). Now you are ready to do the conversion from base 16 to base 10. As an example BF(16) = 11*16^1+15*16^0 = 176+15 = 191(10) The conversion in the other direction can be a little tricky but works pretty much the same way. The trick here is to figure out what is the highest weight nonzero digit and then take it from there. What I am trying to say is that 1(10) and 0000001(10) are the same number - the zeros in front are irrelevant. So let us try to convert 71(10) to base 16. First we figure out how many digits this number has in base 16. Well, since 16^0 = 1 < 71, it is clear that the digit to the left of the decimal point is significant, though we do not know what it is yet. Similarly for 16^1. However, 16^2 = 256 > 71, which implies that this number must be 0??(16) where the question marks are yet to be determined. But the 0 is for sure, because if it were nonzero, this number in base 16 would have bigger value than 71(10) does. The same holds for all the digits to the left - they are all zeros. So now the job is to figure out the two remaining digits, again remembering that we want to find the ones with most weight first. Okay, in order to find the leftmost digit (which has 16^1 weight) we need to find the largest digit which, when multiplied by its weight factor, yields a number not greater than 71(10). Again, if the digit is too large there is no hope of this number of base 16 ever representing 71(10). So this digit happens to be 4, thus making the number 4?(16) = 71(10). Now you since you know how to convert from base 16 to base 10, you can check where we are: 4*16^1+?*16^0 = 64+? = 71(10). Thus the digit ? must be 7, and 47(16) = 71(10). The procedure is similar for 3 or more digit numbers except that you have to repeat the step of finding a digit that doesn't make your number greater than what is given in base 10. Now that you know how to convert from base 10 to base 16 and back, the question of addition and subtraction is simple. Convert the numbers to base 10, add/subtract, and then convert back to base 16. But there is also a slightly quicker but trickier way to do this, and it is exactly the same as when you add/subtract numbers of base 10. So, let's review: 35 +17 --- 52 Easy, but what is important to note here is the mechanism. First you add 5 and 7 to get 12, but the first spot is for digits of weight 1(=10^0) so you put a 2 there, and "carry the 1" since the 1 represents digit 1 of weight 10(=10^1). Now, you add 3 and 1 and the carryover 1 to get 5. Adding in base 16 is very similar: 1A(16) +28(16) --- ??(16) Much as in the case of base 10, you add A to 8 and get 18(10), but you need to put only one digit down. Since 18 is bigger than any of the digits of base 16 (remember there are A..F, too) you realize that this becomes a two digit number, 12(16). Can you verify this? So the one digit you put down is of course 2, and you carry the 1, since it represents a digit of weight 16^1. Now, 1 and 2 and the carryover 1 add up to 4(16), which makes your addition work out to 42(16). And the subtraction works in an exactly the same manner. Hope this was of some use! -Doctor Marko, The Math Forum Check out our web site! http://mathforum.org/dr.math/ |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/