Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:18:38+00:00 2026-06-03T12:18:38+00:00

I would like to encode data into a binary format in a buffer which

  • 0

I would like to encode data into a binary format in a buffer which I will later either write to a file or transfer over a socket. What C# class or classes would be best to use to create a List<byte> containing the binary data.

I will be storing integers, single byte character strings (i.e., ASCII), floating point numbers and other data in this buffer in a custom encoded format (for the strings) and regular binary numeric layout for the ints and floating point types.

BinaryWriter looks like it has the methods I need, but it has to manage a growing buffer for me that I want to produce a List<byte> result from when I am done encoding.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:18:39+00:00Added an answer on June 3, 2026 at 12:18 pm

    BinaryWriter, writing to a MemoryStream. If you need more than the available memory, you can easily switch to a temporary file stream.

    using (var myStream = new MemoryStream()) {
        using (var myWriter = new BinaryWriter(myStream)) {
            // write here
        }
        using (var myReader = new BinaryReader(myStream)) {
            // read here
        }
    
        // put the bytes into an array...
        var myBuffer = myStream.ToArray();
    
        // if you *really* want a List<Byte> (you probably don't- see my comment)
        var myBytesList = myStream.ToArray().ToList();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is a way i can encode information into a binary file using BinaryWriter.
I'm writing an obj-c app and would like to upload a binary file a
I have a binary file which i want to embed directly into my source
I would like to encode some plain text using Ruby and the Crypt library
I would like to use PKCS7 encryption to encode a value together with Java
Would like to make anapplication in Java that will not automatically parse parameters used
I have the following string that I would like to Huffman-encode and store efficiently
It seems like I would be jumping through hoops to move data from MySQL
I'm interested in finding an algorithm that can encode a piece of data into
we have a form which inserts event data into mysql table, this then feeds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.