Adding HexadecimalsDate: 07/13/98 at 23:21:18 From: Cameron Donaldson Subject: How to use the Hexadecimal system Hi. I am currently learning Java. I have came to a section in the book where I have to learn the hexadecimal system. I seem to understand it until it comes to adding them. The book gives an example of 1A + 2E. I get 38 as an answer, but the book says the answer is 48. I got my conclusion using the following method: 1A + 2E = 1(10) + 2(14) = 10 + 28 = 38 I have tried other methods, but have had no luck in finding 48 as the answer. Please help, Dr. Math. - Cam Date: 07/14/98 at 00:11:34 From: Doctor Mike Subject: Re: How to use the Hexadecimal system Hi Cam, You already seem to know that A, B, C, D, E, and F are the hex digits that stand for the decimal (base 10) numbers 10, 11, 12, 13, 14 and 15, respectively. The digits in base 10 stand for powers of ten, but the digits in base 16 stand for powers of 16, so you need more of them. For example, 123 in base 10 means 3*1 + 2*10 + 1*100 and 123 in base 16 means 3*1 + 2*16 + 1*256. Now, for your problem: 1a + 2e = (1*16 + 10) + (2*16 + 14) = 26 + 46 = 72 But remember that everything to the right of the first = is in base 10. If you want to represent 72 in hex, we figure out that: 72 = 64+8 = 4*16+8 which you write as 48 as a hex number. I you want to get a bit adventuresome, you can do all the addition directly in hex. You just have to know the hex addition fact that a + e = 18. What that really means is that if you add 10, which equals a in hexadecimal notation, to 14, which equals e in hexadecimal notation, you get 24, which equals 18 in hexadecimal notation. Another thing you might need is a reminder of what is really going on with ordinary "carrying" in addition. Let's add 15 and 17. To do that you first add the digits in the "ones" column to get 12. You write the 2 (from the 12) down below, and carry the 1 (from the 12) to the "tens" column, getting: 1 1 5 1 7 ----- 2 Then you add all the stuff in the tens column, getting 3, and you write the 3 down below, so the answer is 32. For hex, the process is the same, keeping in mind that you have additional digits that we could use. So, in a hexadecimal system, you would get 5 + 7 equalling the hex digit c, leaving nothing to carry: 1 5 1 7 ----- c To finish this, add the digits in the "sixteens" column and write it down below, for the final hex answer of 2c. In your original problem you do have to carry, but the second column is now the "sixteens place" in hex. It goes like this: 1 1 a 2 e ----- 8 Then when you add all the numbers in the "sixteens" place you get 4, so when you write that down below you get the hex answer 48. Sometimes in computer-related applications base 8 is used instead of base 16 or base 10. Here, the place values for the numbers are powers of 8 (1, 8, 64, etc.). Then the only digits used are 0, 1, 2, 3, 4, 5, 6 and 7. Also, also you may see base 2 (binary) used, where the only digits used are 0 and 1. For this system, the places represent powers of 2 (1, 2, 4, 8, etc.). I hope this helps. - Doctor Mike, The Math Forum Check out our web site! http://mathforum.org/dr.math/ Date: 07/14/98 at 00:43:12 From: Cameron Donaldson Subject: Re: How to use the Hexadecimal system Dr. Mike, Thanks for your earlier response. I'm starting to understand this some more. I have one more question. Why does A + E = 18? How does that work? Date: 07/14/98 at 01:25:09 From: Doctor Mike Subject: Re: How to use the Hexadecimal system Hi again, Glad to see you are sticking with this until you really understand. Okay, here's the reason. The hex number A means the same as the ordinary number 10. The hex number E means the same as the ordinary number 14. If you add the ordinary numbers 10 and 14 together you get the ordinary number 24. So, how do you represent the ordinary number 24 using the hexadecimal system? It is equal to ordinary 16 + ordinary 8. You have one sixteen and 8 ones. You put the hex number together to reflect that, namely, put a 1 is the "sixteens place" and an 8 in the "ones place," giving 18 in hexadecimal notation. It's important to realize that, even though this looks as if it could be the ordinary base 10 number 18, it is not. This is the hexadecimal number 18. Hexadecimal 18 equals ordinary 24, in base 10. - Doctor Mike, The Math Forum http://mathforum.org/dr.math/ Date: 07/14/98 at 01:45:16 From: Cameron Donaldson Subject: Re: How to use the Hexadecimal system You're being a great help. I think I almost have it. Can you send me a couple of questions with answers just to see if I can do them? -Cam Date: 07/14/98 at 01:56:49 From: Doctor Mike Subject: Re: How to use the Hexadecimal system Hi. Try these: 1. F + F = 1E 2. 5 * 5 = 19 3. BEAD - 4321 = 7B8C 4. BEAD + 4321 = 101CE 5. 10000 - 1 = FFFF - Doctor Mike, The Math Forum Check out our web site! http://mathforum.org/dr.math/ Date: 07/14/98 at 15:24:33 From: Cameron Donaldson Subject: Re: How to use the Hexadecimal system This is great! 1. F + F = 1E My solution: F + F = 15 + 15 = 30 I then took 30 and asked how many 16's go into 30? Only one 16 goes into 30, with 14 left over, and 14 in hex form is E. Therefore, the answer is 1E. 2. 5 * 5 = 19 My solution I found this out sort of the same way as the first one. I multiplied 5 * 5 and got 25. I then asked how many 16's go into 25? Again only one does, with 9 remaining. I put the 1 and 9 together to get 19. 3. BEAD - 4321 = 7B8C My solution - I made a table to help me out: BEAD is 11 14 10 13 4321 is 04 03 02 01 Next, I translated everything into base 10. So BEAD in base 10 is 11*4096 + 14*256 + 10*16 + 13*1 = 48813 and similarly, 4321 in base 10 is 17185. I then subtracted 17185 from 48813 and to get 31628. Then I set up another table and did some dividing. I asked how many 4096's go into 31628? I got 7 as an answer. I then took the remainder and asked, how many 256's go into it? I got 11. Continuing, I got the following table: 4069 256 16 1 ----------------------- 7 11 8 12 Then I converted the results into hexadecimal notation and got 7B8C. 4. BEAD + 4321 = 101CE Using some of the results in number 3, I added the following: 48812 + 17185 = 65998 Using the same dividing technique as in the previous problem, I get the following table: 65536 4096 256 16 1 --------------------------- 1 0 1 12 14 I then converted teh result to hexadecimal notation and got 101CE. 5. 10000 - 1 = FFFF I need some help with this one. -Cam Date: 07/14/98 at 18:44:05 From: Doctor Mike Subject: Re: How to use the Hexadecimal system I'm glad you are getting up to speed. You are ready for the next step. Let me compare this to learning a foreign language. For a while you are learning basic constructions and vocabulary. Then for a while you think in English and mentally translate into the other language before you speak. But when you start thinking directly and dreaming in the other language you know you have "arrived." You have done well, but let me show you how to think directly in the hexadecimal system. Let's do the big addition problem. I'll write it in the usual way for addition. Warning: every number you see is going to be a hexadecimal number. There are no decimal base 10 numbers below. The original problem looks like this: B E A D + 4 3 2 1 ---------- The first thing is add the ones column, D + 1 = E: B E A D + 4 3 2 1 ---------- E Then add the two digits in the 16's column, A + 2 = C: B E A D + 4 3 2 1 ---------- C E This is just like the way you do regular ordinary addition in base 10 except that there are more digits. Next we tackle the digits in the 256's column. We get E + 3 = 11. Sometimes, it helps to count out the addition. When adding 3 to E, I start at E and count: F, 10, 11. This 11 is not your ordinary 11, it is hex 11. Just like ordinary addition, you only write down one digit on the bottom, and then carry to the next place. It comes out like this: 1 B E A D + 4 3 2 1 ---------- 1 C E Finally, add all the digits in the 4096's column, including the carry amount, and write that down below. Since 1 + B + 4 = 10, write down: 1 B E A D + 4 3 2 1 ---------- 1 0 1 C E It is a lot easier and faster this way, and you will have the satisfaction of doing it in the "insiders" way! Your way was not wrong, just a lot messier than it had to be. I'm going to ask you to have another try at problem 5, but I will give you some hints. "F" is the largest digit in hex. "9" is the largest digit in ordinary base 10 system. In ordinary base ten we know that that 10000 - 1 = 9999. Good luck and best regards, - Doctor Mike, The Math Forum Check out our web site! http://mathforum.org/dr.math/ Date: 07/14/98 at 19:17:44 From: Cameron Donaldson Subject: Re: How to use the Hexadecimal system I now understand the BEAD + 4321 style of adding, but I still am not clear on question 5. Someone explained it to me this way. What is F + 1? I replied 10. Then they asked me, what is 10 - 1? I said F. Now, when you subtract 1 from 10000 you have to borrow, and when you borrow, you end up subtracting 1 from from each column, so each digit becomes and F. Am I right ? -Cam Date: 07/14/98 at 20:16:06 From: Doctor Mike Subject: Re: How to use the Hexadecimal system Hello again, Come to think of it, problem 5 was probably a little unfair at this stage, because it uses one aspect of arithmetic that many people are a little uncomfortable with. I'm speaking of borrowing, which is sort of the opposite of carrying. I think you will remember if I give you a simple example in ordinary base 10 arithmetic: 34 - 6 ---- You can't take 6 from 4, so you borrow a ten from the tens column (cross out 3 and write 2 above it). Now you have available 14 (original 4 plus the 10 you borrowed) in the ones column. You can take 6 from 14, getting 8, so you write: 2 X 14 - 6 ----- 8 Next, you have only 2 in the tens column, with nothing to subtract, so you write the 2 down below, and the answer is 28. I hope this is at least a little familiar to you. If this had been a hex subtraction problem, almost all of what I said would be the same. You still cannot subtract hex 6 from hex 4. You still will want to borrow from the next place (3 becomes 2) and use that in the ones place. You still have 10 (hex 10 that is) in the ones place. But when you subtract hex 6 from hex 14 you get hex E, not decimal 8, so you write: 2 X 14 - 6 ----- E Continue as before, and the final answer is hex 2E. Neat, eh? For the problem I gave you of 10000 - 1 = FFFF is the same idea really, but it gets a little tricky. But before we put that completely away, we should think of it in another useful way, by counting. When you count in hex, starting at 7 say, it goes like this: 8,9,A,B,C,D,E,F,10,11,12,13,14,15,16,17,18,19,1A,1B, .... When you count in hex, starting at FFF8, it goes like this: FFF8, FFF9, FFFA, FFFB, FFFC, FFFD, FFFE, FFFF, 10000, 100001, ... To convince yourself of that fact, think carefully about carrying, and do this problem: F F F F + 1 ---------- 1 0 0 0 0 I'll get you started on the first step. If you add together what is in the ones column you get F + 1 = 10 (remember, everything in hex here). You write the 0 down below in the ones position in the answer, and carry the 1 of the hex ten up to the next place. It looks like: 1 F F F F + 1 ---------- 0 The carrying just ripples along to the far left end. It is very similar to what happens in ordinary arithmetic when you add one to 9999. You have to do a lot of carrying, and you end up with 10000 in base 10. If you accept the fact that: FFFF + 1 = 10000 in hex, then subtracting 1 from both sides of that equation gives: FFFF = 10000 - 1 How about a joke to wrap up? Q: What did the zero (0) say to the eight (8)? A: Nice belt! That's about it. - Doctor Mike, The Math Forum Check out our web site! http://mathforum.org/dr.math/ Date: 07/15/98 at 00:38:23 From: Cameron Donaldson Subject: Re: How to use the Hexadecimal system Well. I'd like to thank you so much for helping me out. This has got to be one of the trickiest problems I have ever had to face. Thanks again. -Cam |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994- The Math Forum at NCTM. All rights reserved.
http://mathforum.org/dr.math/