?
Solved

byte to byte[]

Posted on 2004-10-22
5
Medium Priority
?
340 Views
Last Modified: 2010-04-15
I am programming a modem communication software and I am receiving data as byte values (one by one) Is there any possibility to append each byte value to the end of some byte array, preferably not fixed in size ? (I know it is possible if I append bytes as characters to some string and then use encoding.getbytes from it ...but there is a problem - ENCODING = CONVERT > scrambling of some byte values above 128).
Thank you!
0
Comment
Question by:ssdjgru1
  • 3
5 Comments
 
LVL 5

Expert Comment

by:tomasX2
ID: 12379349
       System.Collections.ArrayList byteArrayList = new System.Collections.ArrayList();
        byte myByte = 1;
        byteArrayList.Add(myByte);
        byte[] bytesArray = byteArrayList.ToArray(typeof(byte));
         
0
 

Author Comment

by:ssdjgru1
ID: 12379418
byteArrayList.ToArray(typeof(byte));  - Returns system.array, not byte[]
0
 
LVL 5

Expert Comment

by:tomasX2
ID: 12379456
     System.Collections.ArrayList byteArrayList = new System.Collections.ArrayList();
      byte myByte = 1;
      byteArrayList.Add(myByte);
      byte[] bytesArray = new byte[byteArrayList.Count];
      byteArrayList.CopyTo(bytes,0);
0
 
LVL 5

Accepted Solution

by:
tomasX2 earned 1000 total points
ID: 12379481
     System.Collections.ArrayList byteArrayList = new System.Collections.ArrayList();
      byteArrayList.Add((byte)1);
      byteArrayList.Add((byte)2);
      byteArrayList.Add((byte)3);
      byteArrayList.Add((byte)4);
      byteArrayList.Add((byte)5);
      byteArrayList.Add((byte)6);
      byteArrayList.Add((byte)7);
      byte[] bytesArray = new byte[byteArrayList.Count];
      byteArrayList.CopyTo(bytesArray,0);
      foreach( byte b in bytesArray )
      {
        System.Diagnostics.Debug.WriteLine(b);
      }
0
 

Expert Comment

by:sirono
ID: 12379926
ArrayList allTheBytes = new ArrayList();
allTheBytes.add(recievedByte);

(byte[])allTheBytes.ToArray(typeof(byte));

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question