ludy
asked on
How to convert Java's squashBytesToInts() and spreadIntsToBytes() functions in C Sharp?
I'm converting Java code to C-sharp and came across squashBytesToInts and spreadIntsToBytes which is not built-in in C-Sharp. How is it done in C Sharp?
ASKER
Thanks but, the functions used are presented with four parameters:
squashBytesToInts (byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen)
spreadIntsToBytes (int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen)
How would it translate given these four parameters?
squashBytesToInts (byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen)
spreadIntsToBytes (int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen)
How would it translate given these four parameters?
ASKER
I mean 5 parameters
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
static byte[] spreadIntsToBytes(int[] ints)
{
byte[] result = new byte[ints.Length*4];
for (int i = 0; i<ints.Length; i++)
Array.Copy( BitConverter.GetBytes(ints
return result;
}
static int[] squashBytesToInts(byte[] bytes)
{
int size = bytes.Length >> 2; // divide by 4
int[] result = new int[size];
for (int i = 0; i<size; i++)
int[i] = BitConverter.ToInt32(bytes
return result;
}