• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

byte to byte[]

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
ssdjgru1
Asked:
ssdjgru1
  • 3
1 Solution
 
tomasX2Commented:
       System.Collections.ArrayList byteArrayList = new System.Collections.ArrayList();
        byte myByte = 1;
        byteArrayList.Add(myByte);
        byte[] bytesArray = byteArrayList.ToArray(typeof(byte));
         
0
 
ssdjgru1Author Commented:
byteArrayList.ToArray(typeof(byte));  - Returns system.array, not byte[]
0
 
tomasX2Commented:
     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
 
tomasX2Commented:
     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
 
sironoCommented:
ArrayList allTheBytes = new ArrayList();
allTheBytes.add(recievedByte);

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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now