2D array to 1D array conversion

Submitted by:Jhon Smith

Date added:11 April, 2011


Convert a coordinate (x,y) into the index for a 1D array. For example, the coordinate (3,1) would be at array index 8 if there are 5 columns.

Assumption: Arrays start at 0.

Tags: 2d array conversion

Code Snippet:

arrayPosition = (y * numberOfColumns) + x