# Get row/col from index/size

**URL:** <https://forum.kirupa.com/t/get-row-col-from-index-size/329946>\
**Category:** Uncategorized\
**Created:** [November 11, 2012, 4:07am UTC](https://forum.kirupa.com/t/get-row-col-from-index-size/329946 "2012-11-11T04:07:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![reppinfreedom](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@reppinfreedom](https://forum.kirupa.com/u/reppinfreedom)\
**Post date:** [November 11, 2012, 4:07am UTC](https://forum.kirupa.com/t/get-row-col-from-index-size/329946/1 "2012-11-11T04:07:25Z")

</div>

I’m working on some row/col functions for converting back and forth… Is there a simpler way to do this second function? Btw, these appear to be working correctly, but I am not 100% sure they are completely correct.

I’m converting back and forth between rows/cols and index/sizes. The tables are square. The math is done to match flash array’s and vectors which start at index 0.

public static function getTileIndexByRowCol(Col:int,Row:int,mapSize:int):int {  
var Index:int = Row \* mapSize + Col;  
return Index;  
}

public static function getRowColByTileIndex(Index:int,mapSize:int):Object {  
var rowCol:Object = new Object();  
if (Index \> 0) {  
var Num:Number = Index / mapSize;  
var Rem:Number = Number("." + String(Num).split(".")[1]);  
if (isNaN(Rem)) {  
Rem = 0;  
}  
rowCol.Row = Math.floor(Num);  
rowCol.Col = Math.round(Rem \* mapSize);  
} else {  
rowCol.Row = 0;  
rowCol.Col = 0;  
}  
return rowCol;  
}
