Because getValue() sets its addr argument to 0 before using it, it will only ever return the value in mem. I'm not sure what that assignment is for!
As for what "toString()" will display: my head hurts just trying to follow it! Partly this is due to the use of all the "magic numbers" like 17, 9, 8, and 16. Without knowing what these represent, it's impossible to picture what the intent is here.
But this display can't come from the code snippet above; the getValue() method, as shown, will always return the same value (mem). So I don't think we're looking at the code you're actually running.
But now that I see what toString() is supposed to do here, I can see several problems with it. For example, it looks like each row is supposed to show 16 contigous elements with a tab after the first 8. But you're actually skipping an element in the middle of each row; the upper limit of the left half is "< j+8", while the lower limit of the right if "= j+9". The element at index j+8 is skipped. Similarly, although you're printing 16 items in each row, you're incrementing j by 17 each time, so that if you fix the above, the item at the end of each row will be skipped.
In any case, if you fix both of these, you'll see that element at the beginning of the second row wrap back around to be at the end of the first row, which I gather is what you want. [ September 25, 2006: Message edited by: Ernest Friedman-Hill ]
Joined: Feb 03, 2006
fisrt of all here is the new code
test stuff still the same. Now when I run it I see a 5 at the end of the first line and a 5 at the beginning of the second line.
author and iconoclast
Each row has one more element in it than you intend; one element is replicated at the end of the each row and the beginning of the next.
You want to increment j by 16 for each row, which is what you're doing now. It should be 16 since that's how many items you're displaying in a row.
For each row, the first group is indices j+0 through j+7 (i.e., the loop condition is i < j+8), and the second group is indices j+8 through j+15 (i.e., i < j+16). This isn't quite what you're doing; if you adjust your indices accordingly, things should work OK.
I bet graph paper would have helped you work this out. If you marked off a square area of the grid, 16 cells wide, and marked the leftmost element in each row with its index, and then the eighth and ninth with theirs, and the rightmost as well, you would have been able to figure this out.
Joined: Feb 03, 2006
thanks for your help. I did finally figure it out. my numbers where just messed up. thanks for the help.