1 Replies - 975 Views - Last Post: 22 June 2009 - 05:21 AM Rate Topic: -----

#1 yungbol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 09-December 08

ASCII to Int

Posted 21 June 2009 - 02:37 PM

Ok, well I am reading an Int32 with my BinaryReader. The value is stored in hex. I have successfully taken my value in hex, converted the hex to an integer and displayed it.

When the integer get's displayed, it is displayed in a textbox.

Now I need help on converting the string in my textbox and make that an integer. Then from there I need to convert that integer to bytes so I can write it just like it looks when I read it.

Here is my code:

try
			{
				OpenFileDialog ofd = new OpenFileDialog();
				if (ofd.ShowDialog() == DialogResult.OK)
				{
					fileLocation = ofd.FileName;

					fs = new FileStream(fileLocation, FileMode.Open);
					br = new BinaryReader(fs);

					fs.Position = myOffset;
					int x = BitConverter.ToInt32(EndianChange(br.ReadBytes(4)), 0);

					value.Text = x.ToString();

					//Close the stream
					fs.Close();
				}
			}
			catch
			{
				//Nothing on catch
			}



Is This A Good Question/Topic? 0
  • +

Replies To: ASCII to Int

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: ASCII to Int

Posted 22 June 2009 - 05:21 AM

you just need to convert an integer that is displayed in a textbox?

int number = 0;

if (!int.TryParse(textBox1.Text, out number))
{
     MessageBox.Show("Must contain a number");
     return;
}

MessageBox.Show("Number is: " + number.ToString());


This post has been edited by eclipsed4utoo: 22 June 2009 - 05:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1