Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 8th, 2007, 9:09 PM   #1
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
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:

0012FF54
0012FF58
0012ff5C
0012ff60

I 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?
357mag is offline   Reply With Quote
Old Jul 8th, 2007, 9:19 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 925
Rep Power: 4 lectricpharaoh will become famous soon enough
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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Memory question metsfan C 2 Apr 11th, 2006 6:47 PM
When to use the new keyword in C++? titaniumdecoy C++ 28 Mar 16th, 2006 12:36 PM
Pointers in C (Part II) Stack Overflow C 2 Apr 29th, 2005 10:39 AM
Pointers in C (Part I) Stack Overflow C 4 Apr 28th, 2005 7:03 PM
memory leak question xaosai C++ 2 Mar 31st, 2005 10:25 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC