Solved

byte to byte[]

Posted on 2004-10-22
333 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
Question by:ssdjgru1
    5 Comments
     
    LVL 5

    Expert Comment

    by:tomasX2
           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
    byteArrayList.ToArray(typeof(byte));  - Returns system.array, not byte[]
    0
     
    LVL 5

    Expert Comment

    by:tomasX2
         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:
         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
    ArrayList allTheBytes = new ArrayList();
    allTheBytes.add(recievedByte);

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

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    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…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now