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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:37:18+00:00 2026-05-16T08:37:18+00:00

I am trying to edit a line of a text file (.Hex file) containing

  • 0

I am trying to edit a line of a text file (.Hex file) containing all Hex characters without using pointers and in a more efficient way.

It takes so long because the program I have to edit some (around 30×4 bytes or 30 float values from the address values of hex file).

Every time the program replaces one byte, it searches the complete file and replaces the values, and copy back back again the new file to another file. This process repeats 30 times, which is quite time consuming and hence not looks appropriate.

What would be the most efficient method?

public static string putbyteinhexfile(int address, char data, string total)
{

    int temph, temphl, tempht;
    ushort checksum = 0;
    string output = null, hexa = null;
    StreamReader hex;
    RegistryKey reg = Registry.CurrentUser;
    reg = reg.OpenSubKey("Software\\Calibratortest");
    hex = new StreamReader(((string)reg.GetValue("Select Input Hex File")));
    StreamReader map = new StreamReader((string)reg.GetValue("Select Linker Map File"));
    while ((output = hex.ReadLine()) != null)
    {
        checksum = 0;
        temph = Convert.ToInt16(("0x" + output.Substring(3, 4)), 16);
        temphl = Convert.ToInt16(("0x" + output.Substring(1, 2)), 16);
        tempht = Convert.ToInt16(("0x" + output.Substring(7, 2)), 16);
        if (address >= temph && 
            address < temph + temphl && 
            tempht == 0)
        {
            output = output.Remove((address - temph) * 2 + 9, 2);
            output = output.Insert((address - temph) * 2 + 9, 
                     String.Format("{0:X2}", Convert.ToInt16(data)));

            for (int i = 1; i < (output.Length - 1) / 2; i++)
                checksum += (ushort)Convert.ToUInt16(output.Substring((i * 2) - 1, 2), 16);

            hexa = ((~checksum + 1).ToString("x8")).ToUpper();
            output = output.Remove(temphl * 2 + 9, 2);
            output = output.Insert(temphl * 2 + 9, 
                                   hexa.Substring(hexa.Length - 2, 2));
            break;
        }
        else total = total + output + '\r' + '\n';
    }

    hex.Close();
    map.Close();

    return total;
}
  • 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-16T08:37:18+00:00Added an answer on May 16, 2026 at 8:37 am

    Assuming you don’t want to massively rewrite your existing logic which does ‘for each line, do this search and replace logic’, I’d think the simplest change would be:

    var lines = File.ReadAllLines(filePath);
    foreach (change to make)
    {
        for (int i = 0; i < lines.Length; i++)
        {
            // read values from line
            if (need_to_modify)
            {
                // whatever change logic you want here.
                lines[i] = lines[i].Replace(...);
            }
        }
    }
    File.WriteAllLines(filePath, lines);
    

    Basically, you’ll still do the logic you have now, except:

    1. You read the file once instead of N times
    2. you get rid of streamreader / streamwriter work
    3. you do your changes on the array of strings in memory
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a text file using jquery, like this: // LOAD
I'm trying to edit a text file that looks like this: TYPE=Ethernet HWADDR=00:.... IPV6INIT=no
Edit: I'm trying to convert a text file into bytes. I'm not sure if
I'm currently trying to edit a text file in c#. This text file is
I'm trying to edit the httpd.conf file located in /private/etc/apache2, and I can't figure
I'm trying to edit a form with a ImageField and I´m using modelformset_factory in
I am trying to edit the wikitext of a page using a textView and
I am trying to make a disorganized text file into a list suitable for
I am trying to create a simple batch file that will replace a line
I'm trying to just get rid of duplicate consecutive words from a text file,

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.