How would you address one dimensional memory using two dimensions?

How would you address one dimensional memory using two dimensions? (Such as getting the value Matrix::ValueAt(row, col) where Matrix stores the values as a one dimensional array (float m[16] for a 4x4 matrix).

class Matrix4x4
{
    private float m[16];

    float getValueAt(int row, int col)
    {
        // I want this function
    }

}

Answers


With m[row * 4 + col], or the other way around.


Need Your Help

Capturing a specific size image from webcam

flash webcam video-capture image-capture

How can I capture an image from the webcam and have it be a specific size, without whitespace?

iOS possible for draggable hide button on UITabbar?

ios uitabbarcontroller uitabbar

Is it possible to add a custom button ontop of a tabbar which can be used to hide and show the tabbar?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.