3

I have a byte array of

byte[] d = new byte[64];

now i want to convert it to a 2d byte array like ..

byte[,] data = new byte[8,8];

can any one help me on this

3 Answers 3

6

This could be one of method.

byte[] d = new byte[64];
byte[,] data = new byte[8,8];

int row = 0;
int column = 0;

for(i=0; i < d.Length; i++)
{
   row = i%8;
   column = i/8;
   data [row, column] = d[i];    
}
Sign up to request clarification or add additional context in comments.

4 Comments

yeah thanks but need some editing if u permit me i will do it in the ans .. it worked for me thanks
You can or You can tell me so that I would make that.
make it d.Length and data[column,row] thats it
Thanks @Drone, So nice of you. Made those changes.
4

You can use the Buffer.BlockCopy Method:

byte[] d = new byte[64];
byte[,] data = new byte[8,8];

Buffer.BlockCopy(d, 0, data, 0, 64);

Comments

0

How about something like

byte[] d = new byte[64];

for (byte i = 0; i < d.Length; i++)
    d[i] = i;

byte[,] data = new byte[8, 8];

Enumerable.Range(0, 8).ToList().
    ForEach(i => Enumerable.Range(0, 8).ToList().
        ForEach(j => data[i, j] = d[i * 8 + j]));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.