Login Register






[C#] Split Byte[] Into Chunks filter_list
Author
Message
[C#] Split Byte[] Into Chunks #1
I was developing a Crypter some time ago and I needed to split the payload in-to multiple byte[].

Code:
static List<Byte[]> SplitIntoChunks(Byte[] arr_bInput, Int32 iSize) { List<Byte[]> lstChunks = new List<Byte[]>(); List<Byte> lstChunk = new List<Byte>(); for(int i = 0; i < arr_bInput.Length; i++) { lstChunk.Add(arr_bInput[i]); if (i == iSize - 1 || i == arr_bInput.Length - 1 ) { lstChunks.Add(lstChunk.ToArray()); lstChunk.Clear(); } } return lstChunks; }

Nothing advanced, but maybe someone needs this.

What it does?

If you have a Byte[] with Length of 8 and you specify Size to 6
You will then have Two Byte[], one with Size of 6 and the other of 2.

Reply

RE: [C#] Split Byte[] Into Chunks #2
There's better ways to copy blocks of an array to a generic list than to utilize a secondary list instance.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply