![]() |
Hexadecimal Memory Address Question
I've got this program that just shows a little bit about pointer arithmetic. Using an array and a pointer, I just output the memory address of the first element using the pointer, then I incremented the pointer by 1 to output the next memory address, then I incremented the pointer by 1 again to output the next memory address. Then I used a second pointer and assigned it the memory address of the last element in my array. Then I outputted the memory address of that. I had to do a little digging in my book to try to understand the output. Here it is:
:
0012FF54I was using an integer array so the elements were 4 bytes. Going from the first element to the second, I understood the 4 moving to the 8, makes sense to me. Moving from the second element to the third, I did not understand the 8 moving to the C. But then I did a little reading on hexadecimal numbering and I think I understand why now. Hexadecimal has 16 digits, but when you get to 10 then you say A, 11 is B, 12 is C. So moving 4 bytes up from 8 would land you precisely on the letter C. Then to understand moving from the third element to the last element you count again starting at C, D is one beyond that, E is two beyond that, F is three beyond that, and then finally back to 0 would land you at 4 bytes beyond that. So that's how I got it figured. My question is moving from the 5 to the 6(in the third to the fourth element). Is this just simply the way it works? It's just simply the way the consecutive elements would be numbered? And just accept it for what it is and not try to analyze it too much? |
It's just the next higher digit rolling over. If you have the number 19 in decimal, and you add one, you get 20; because you 'wrapped' the 'ones' digit, the 'tens' digit increases.
Same with hexadecimal. The only difference is that each digit has 16 possible values (0, 1, 2 ... D, E, F), rather than only ten. You still must increment the next higher place when one wraps from F to 0. I suggest you read up on different based numbering systems. In programming, decimal (base-10), binary (base-2), hexadecimal (base-16) and to some extent octal (base-8) are the ones you need to be familiar with. |
| All times are GMT -5. The time now is 2:45 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC