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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:54:12+00:00 2026-05-15T18:54:12+00:00

How do I use WriteByte? The below code will not work, coming up with

  • 0

How do I use WriteByte? The below code will not work, coming up with both a CS1502 error, and a CS1502 error at the “stream.WriteByte(totalSeasons);” line. It’s frustrating because I am incredibly close to finishing this program.

Essentially, my problem is that I need to write binary data to a file on the click of a button. I can just write this for example: stream.WriteByte(0xCD); The problem is that I need to allow the user to type in the data they want to be written into a textbox, and then on the click of a button the data will be converted from decimal to hex, and then put in. I think I’ve figured the conversion part out, but I can’t edit the binary with the data because it seems that WriteByte can only write Hex values like 0xCD, and there seems to be no way to store the hex value and still write it. I’ve tried stream.WriteByte(ByteName); but that comes with the errors described above.

void BtnTotalSeasonsClick(object sender, EventArgs e)
{
    using (var stream = new FileStream(drvFile, FileMode.Open, FileAccess.ReadWrite))  
    { 
        System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
        Byte[] totalSeasons = enc.GetBytes(txtTotalSeasons.Text);
        stream.Position = 4; 
        stream.WriteByte(totalSeasons);
    } 
}
  • 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-15T18:54:13+00:00Added an answer on May 15, 2026 at 6:54 pm

    totalSeasons is more than one byte, so you’d call the Write method which writes an entire block of bytes.

    Is txtTotalSeasons.Text supposed to turn into a single byte? Maybe you’re looking for Byte.TryParse instead of Encoding.GetBytes.

    EDIT: Provide the entire error message, not just the number. Also, what exactly is in the text box. You seem to be confused about hex vs decimal vs binary vs ASCII. They are different string representations of a number.

    0xCD is not a hex value. It is a C#-conformant hexadecimal representation of a number. (Another hexadecimal representation, not allowed by C#, is CDh). The compiler turns it into a number in the .NET internal format (which happens to be binary, but this isn’t important). Then the WriteByte or Write call stores the number into the file in binary. You’d get the same result from stream.WriteByte(0xCD), stream.WriteByte(206), or stream.WriteByte(0316) since the compiler converts all of them to the same internal representation. If you want to write a variable then there’s no reason to use hex at all, you need the internal representation which WriteByte expects.

    You said that the user enters a number between 0 and 255, in decimal? Then the conversion required is from a decimal string representation to the internal representation, this is called “parsing”.

    Try this code:

    stream.WriteByte(Byte.Parse(txtTotalSeasons.Text));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use the following code to retrieve and decompress string data from Amazon
What is the point of the synchronization here? Why not just use mConnectedThread.write(out) ?
I get the following error when trying to use Response.Redirect in one of my
I have a UDA in SQL 2005 that keeps generating the below error. I'm
... if I use an IDisposable in a local variable, but do not call
I'm trying to use the JPGEncoder class in flash AS3 but this error keeps
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;

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.