title: How to calculate index from row and column?
body: <p>I want to calculate an index (base 0) for any given row and column where rows and columns are base 1 and the number of columns is known, e.g. 2</p>
  <p>If max_columns is 2 and index is 5, then to calculate row number from an index:</p>
  <pre><code>Row = (index % max_columns) + (int)(index / max_columns)
      = (5 % 2) + (int)(5 / 2)
      = 1 + 2
      = 3
  </code></pre>
  <p>To calculate column number from index</p>
  <pre><code>Col = max_columns - (index % max_columns)
      = 2 - (5 % 2)
      = 2 - 1
      = 1
  </code></pre>
  <p>Question is how to calculate row and column from any index where the index is base 0.  This is to calculate an index into an array in a java application.</p>
  <p>The correct solution for me as supplied by 'Willem Van Onsem':</p>
  <p>Where <code>Row</code> is 3, <code>Col</code> is 2 and <code>max_columns</code> is 2:</p>
  <pre><code>Index = (Row * max_columns) + Col - max_columns - 1
        = (3 * 2) + 2 - 2 - 1
        = 6 + (-1)
        = 5
  </code></pre>