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 835173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:47:03+00:00 2026-05-15T04:47:03+00:00

I’m trying to create a binary file from a intelHex file. Iside the intelHex

  • 0

I’m trying to create a binary file from a intelHex file. Iside the intelHex file I have data and address to which I should write the data inside the binary file.
IntelHex file looks like that

:10010000214601360121470136007EFE09D2190140
:100110002146017EB7C20001FF5F16002148011988
:10012000194E79234623965778239EDA3F01B2CAA7
:100130003F0156702B5E712B722B732146013421C7
:00000001FF

So I have 4 lines here with data since the last one tells us thats the end of file.
Here is what I’m doing to create the file

        while (!streamReader.EndOfStream)
        {
            string temp = String.Empty;
            int address = 0;
            line = streamReader.ReadLine();
            // Get address for each data
            address = Convert.ToInt32(line.Substring(3, 4), 16);
            // Get data from each line
            temp = line.Substring(7, 2);
            if (temp == "01")
                break;
            else
            {
                temp = line.Substring(9, line.Length - 11);
                string[] array = new string[(temp.Length / 2)];
                int j = 0;
                for (int i = 0; i < array.Length; ++i)
                {
                    array[i] = temp[j].ToString() + temp[j + 1].ToString();
                    j = j + 2;
                }
                temp = String.Empty; 
                for (int i = 0; i < array.Length; ++i)
                {
                    temp = temp + Convert.ToChar(Convert.ToInt32(array[i], 16));

                }
            }
            binaryWriter.Seek(address, SeekOrigin.Begin);
            binaryWriter.Write(temp);
            binaryWriter.Flush();
        }
        Console.WriteLine("Done...\nPress any key to exit...");

The problem here is, that data in binary file in some places is not equal to data from the intelHex file. Looks like there is some random data added to the file and I do not know from where. First time I saw that there is an additional data before the data from the intelHex file. For instance first data line starts with 21, but in binary file I have a number 12 before the 21. I do not know what is wrong here. Hope someone can help me or guide me where I can find some usefull informations about creating binary files in C#

  • 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-05-15T04:47:04+00:00Added an answer on May 15, 2026 at 4:47 am

    <Generic answer pointing out that a Unicode character (char) is not an octet (byte), and that the code produces the wrong output because binary data is written as Unicode string to the file.>

    Hint: use a byte[] for binary data, not a string.

    Also: In before answers suggesting to use a StringBuilder for the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 487k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got past it by using the LoadComplete event to… May 16, 2026 at 8:13 am
  • Editorial Team
    Editorial Team added an answer You need to submit the <form>, so your content is… May 16, 2026 at 8:13 am
  • Editorial Team
    Editorial Team added an answer Set the defaultDate parameter. This works if the attached field… May 16, 2026 at 8:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Related Questions

No related questions found

Top Members

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.