-
Trouble in Math Land
Hello Math Gurus
i Have been trying to solve this for 4 days now..Its time I accept ..I need help
Here is the problem
Lets say i have an aaray in C say a[256][256][124]
hence a[0][0][0]=0
a[1][0][0]=1
and so on and so forth
therfore i can get a generalised formula for calculating the linear index number as ;-
[(z*65536)+(y*256)+x]=index number
now lets say i have an index number 18921 how do i get the original x,y and z co-ordinates
Help needed
-
Taking your example, [(z*65536)+(y*256)+x]=index number=18921 we notice that the LHS leaves remainder x on division by 256. So x is the remainder of 18921 on division by 256, that is, 233. So z*65536 + y*256 + 233 = 18921, that is, z*65536 + y*256 = 18688 = 73*256. So z*256 + y = 73. The LHS leaves remainder y on division by 256, so y = 73. We now have z*256+73 = 73, giving z=0.