No.
There is no re-dimension facility in C#.
Instead, create a new array and use
Array.Copy[
^] to transfer the original values.
private T[] shrinkArray<T>(T[] oldArray, int newLength)
{
T[] newArray = new T[newLength];
Array.Copy(oldArray, newArray, newLength);
return newArray;
}
"But it loses original data in array of 900 length. What you say now?"
Oops! Sorry - I missed that you were trying to pack the bits!
Try this: (untested)
private static int[] PackBits(int[] inp)
{
int intsRequired = (inp.Length + 31) / 32;
int[] outp = new int[intsRequired];
int curOut = 0;
for (int i = 0; i < inp.Length; i++)
{
outp[curOut] = (outp[curOut] << 1) | inp[i];
if ((i % 32) == 31)
{
curOut++;
}
}
return outp;
}
"Well, it works fine. Thanks :)
Now,my next question is how to unpack it (get original back)????"
Well, the Haynes Book of Lies always suggests that "reassembly is the reverse of disassembly".
I used to hate that! But it is true.
I have revised the PackBits so it is easier to unpack when the data doesn't fit exactly into a complete int:
private static int[] PackBits(int[] inp)
{
int intsRequired = (inp.Length + 31) / 32;
int[] outp = new int[intsRequired];
int curOut = 0;
for (int i = 0; i < inp.Length; i++)
{
outp[curOut] |= inp[i] << (i % 32);
if ((i % 32) == 31)
{
curOut++;
}
}
return outp;
}
private static int[] UnpackBits(int[] inp, int len)
{
int intsRequired = inp.Length * 32;
int[] outp = new int[intsRequired];
int curOut = 0;
foreach (int val in inp)
{
uint x = (uint) val;
for (int i = 0; i < 32; i++)
{
outp[curOut++] = (int) ((x >> i) & 1);
}
}
return outp;
}