use*_*017 1 c c++ arrays command-line matrix
我有一个byte array由单个索引索引的i。但是这个数组将在屏幕上显示为array of array(不是矩阵,因为并非所有行都具有相同的维度)。使用箭头键,我可以“浏览”“矩阵”的这些元素。所选元素将具有不同的背景颜色。为此,我将需要要突出显示的字节rows和columns。
因此,我需要有关公式的帮助来转换行和列的单个索引。
我已经为按键创建了逻辑,即当可以向某个方向移动时,只需要在屏幕上显示即可。
完整行的长度为 8 个字节。
在这种情况下,数组是:
unsigned char test[] = {0x00, 0x01, 0x02, 0x03, 0x61, 0x62, 0x63, 0x07, 0x21, 0x09, 0x0A};
Run Code Online (Sandbox Code Playgroud)
它会以这种方式出现:

要获得知道列、行和行长度的索引,您只需执行以下操作:
I = Row * LineLenght + Column;
Run Code Online (Sandbox Code Playgroud)
反面如下:
Row = I / LineLenght; // Integer division
Column = I % LineLenght; // Reminder of the division of I by LineLenght
Run Code Online (Sandbox Code Playgroud)
这是基本的算术:)
您必须确保永远不会超出数组大小。