T
Tomas Deman
Hi,
I need a fast method for converting an int array to a byte array.
At the moment, I'm using this:
public static byte[] Int2ByteArray(int[] array)
{
byte[] lbytRetval = new byte[array.GetLength(0) * 2];
int lintIdxHi;
int lintIdxLo;
for (int i = 0; i < array.GetLength(0); i++)
{
lintIdxHi = (i * 2);
lintIdxLo = lintIdxHi + 1;
lbytRetval[lintIdxLo] = (byte)(array % 0xff);
lbytRetval[lintIdxHi] = (byte)((array - lbytRetval[lintIdxLo]) /
0xff);
}
return lbytRetval;
}
I was thinking of using Marshal.Copy but can't get it to work.
I need a fast method for converting an int array to a byte array.
At the moment, I'm using this:
public static byte[] Int2ByteArray(int[] array)
{
byte[] lbytRetval = new byte[array.GetLength(0) * 2];
int lintIdxHi;
int lintIdxLo;
for (int i = 0; i < array.GetLength(0); i++)
{
lintIdxHi = (i * 2);
lintIdxLo = lintIdxHi + 1;
lbytRetval[lintIdxLo] = (byte)(array % 0xff);
lbytRetval[lintIdxHi] = (byte)((array - lbytRetval[lintIdxLo]) /
0xff);
}
return lbytRetval;
}
I was thinking of using Marshal.Copy but can't get it to work.