Take this image: http://ScrnSht.com/nkvusq
How can i get the position of tile 14 (or any other) when only knowing the following:
Tile ID: 14
The end result should be 2x4.
so in most programming languages your example would be:
Such a bijective mapping is much easier to express if your tile indices and rows/columns are zero-based.
If you look at the column numbers, as the column number increases by one, so does the tile index. More particularly, there's a pattern that for each row, it starts on a multiple of the row width, and increases by one.
This means that if we could get rid of that term, we would have our column number.
The modulus operator (commonly % in most languages) will take a number in a range [0,n) and map it to the values 0 through n-1, wrapping around.
A suitable expression for the column index is thus
For the row, we need an expression that results in the same value for all values in the row. An operation related to modulus is division, so it's likely useful.
So in summary: