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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:00:42+00:00 2026-06-03T01:00:42+00:00

I want to know how I would convert from a decimal number located in

  • 0

I want to know how I would convert from a decimal number located in a text box to hexadecimal and then to a byte array and write this array to the offset I want, using BinaryWriter.

My textBox11 decimal value is “101200001” and I need to write the it’s Hexadecimal value, which is “06 08 30 81”, into a file at a speciffic offset.

This is the what I have, but I’m missing the conversion from textBox11.Text to byteArray.

    int index = listBox1.SelectedIndex;
    int startOffset = 0x00000008;
    int itemIDDiff = 0x00000328;

    BinaryWriter bw = new BinaryWriter(File.Open(_FileName, FileMode.Open));
    bw.BaseStream.Seek(startOffset + itemIDDiff * index, SeekOrigin.Begin);
    bw.Write( /* textBox11.Text converted to HEX then to byte array? */ );
    bw.Close();

This is part of the file that I need to write to:

00000330h: 02 00 00 00 00 00 00 00 4A 61 64 65 20 45 61 72 ; ........Jade Ear
00000340h: 72 69 6E 67 00 00 00 00 00 00 00 00 00 00 00 00 ; ring............

let’s say I want to change the “02 00 00 00” to “06 08 30 81”. How would I do this using the BinaryWriter?

  • 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-03T01:00:44+00:00Added an answer on June 3, 2026 at 1:00 am

    You can’t convert decimal to Hex (how would you deal with the fraction portion?). But you can use Int64 (a long) instead:

    var text = "101200001";
    var asLong = Convert.ToInt64(text);
    var asHex = asDecimal.ToString("X");
    

    asHex now has the hex string you’re after.

    But the problem you have is that ‘hex’ is really just a way of viewing a set of raw bytes on disk. And the way a number is represented in raw bytes depends on the program itself. If you’ve got a binary writer, you just need to know the byte representation of the number you’re trying to write. This may be enough by itself (without converting to string):

    bw.Write(asLong);
    

    Looked at this more, and it seems as though you’re after 4-byte numbers, so ints not longs. BitConverter is good, but it writes everything in reverse order to what you may want. So keep these in mind and review the below:

    var text = "101200001";
    var asInt = Convert.ToInt32(text);                    // 4 byte number
    var asBytes = BitConverter.GetBytes(asInt).Reverse(); // same hex representation as a byte array (same order)
    

    And so in your example add this:

    bw.Write(asBytes);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal: I want to convert a number from the format 10.234,56 to 10234.56
What is the correct way to convert my class to/from a byte array? I
I want to know the difference (visually) would be the best between the two
I want to know what the difference is between alt= and name= Would it
I want to know if I'm missing something. Here's how I would do it:
I know that with a large site you would want to separate footers, menus,
Hello I would like to know if my script is good; I want to
I would like to know what I can offer to clients when they want
I know how to convert binary to decimal. I know at least 2 methods:
My scenario should be simple... the type I want to convert FROM is ALWAYS

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.