473,473 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding 2 buffer() bytes together

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()

Nov 21 '05 #1
5 1801
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
"devprog" <de*****@nospam.nospam> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
| 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()
|
|
|
Nov 21 '05 #2
"devprog" <de*****@nospam.nospam> schrieb:
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)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3
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" wrote:
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()

Nov 21 '05 #4
Thank you all for your time to help out here.

Sincerely

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:#A**************@TK2MSFTNGP15.phx.gbl...
"devprog" <de*****@nospam.nospam> schrieb:
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)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
"devprog" <de*****@nospam.nospam> schrieb:
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.).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cylin | last post by:
Dear all, From now on, I just can get a byte twice. Then decode this two bytes. for example, buffer is a unsigned char array. value=(*buffer)<<8; value+=*(buffer+1);
10
by: pembed2003 | last post by:
Hi, If I have the folllowing: char* p = malloc(5); memset(p,-1,5); *p = 0; printf("%d\n",strlen(p)); free(p); It will print 0. Is there a way to retrive the initial size of memory
2
by: Macca | last post by:
Hi, My application uses an asynchronous socket server. The question I have is what i should set my socket server buffer size to. I will know the size of each data packet sent across the...
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
13
by: moondaddy | last post by:
my understanding is that the max value of a byte is 255. Therefore, why does the following code get a compile error? byte val1 = 10; byte val2 = 23; byte ttl; ttl = val1 + val2; //this line...
3
by: Hugh Janus | last post by:
Hi group, I am using a TCPStream together with a FileStream to send a file across a network. Everything works fine except for one thing. Always, at the end of the file there are several lines...
28
by: bwaichu | last post by:
Is it generally better to set-up a buffer (fixed sized array) and read and write to that buffer even if it is larger than what is being written to it? Or is it better to allocate memory and...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
10
by: puzzlecracker | last post by:
Say I want to arrange bytes in the internal buffer in a certain way. I receive those bytes in the socket. One solution is to read in socket in pieces: byte buffer = new byte; int index = 0;...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.