Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

byte to byte[]

Posted on 2004-10-22
5
Medium Priority
?
337 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

972 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