Adding 2 buffer() bytes together

  • Thread starter Thread starter devprog
  • Start date Start date
D

devprog

How do I do something like below? Thanks in adv.

Dim Buffer1() As Byte
Dim Buffer2() As Byte
Dim TotalBuffer() As Byte

TotalBuffer() = Buffer1() & Buffer2()
 
devprog,
The "easiest" way may be to use Array.Copy, something like:

| Dim Buffer1() As Byte
| Dim Buffer2() As Byte
| Dim TotalBuffer() As Byte

ReDim TotalBuffer(Buffer1.Length + Buffer2.Length - 1)
Array.Copy(Buffer1, 0, TotalBuffer, 0, Buffer1.Length)
Array.Copy(Buffer2, 0, TotalBuffer, Buffer1.Length, Buffer2.Length)

Hope this helps
Jay


| How do I do something like below? Thanks in adv.
|
| Dim Buffer1() As Byte
| Dim Buffer2() As Byte
| Dim TotalBuffer() As Byte
|
| TotalBuffer() = Buffer1() & Buffer2()
|
|
|
 
devprog said:
How do I do something like below?

Dim Buffer1() As Byte
Dim Buffer2() As Byte
Dim TotalBuffer() As Byte

TotalBuffer() = Buffer1() & Buffer2()

\\\
Dim a1() As Byte = {1, 2, 3, 4, 5}
Dim a2() As Byte = {6, 7, 8, 9, 10}
Dim a(a1.Length + a2.Length - 1) As Byte
Buffer.BlockCopy(a1, 0, a, 0, a1.Length)
Buffer.BlockCopy(a2, 0, a, a1.Length, a2.Length)
///
 
You can dim totalbuffer to the combined size of the two buffers to add then
use .CopyTo method to copy each of the buffers into the totalbuffer. Note
that CopyTo method has indexes to start copying to/from in the arrarys.
 
devprog said:
Thank you all for your time to help out here.

Note that 'Buffer.BlockCopy' is faster than the methods of the 'Array' class
('Array.CopyTo' etc.).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top