I’m drawing a HUGE blank here.
Everything I’ve found is about getting an index from a given row and column, but how do I get a row and a column from an index?
The row is easy: (int)(index / width).
My brain is suffering massive bleed trying to compute the column.
Shame on me.
For a zero-based index, the two operations are, where
widthis the width of the structure:Those are for C using integers, where the division rounds down and the
%modulo operator gives the remainder. If you’re not using C, you may have to translate to the equivalent operations.If you don’t have a modulo operator, you can use: