Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

how do I read hexadecimal numbers from a file? Or better, how to type them to the file? I tried the System.Convert.ToUInt32( string) function but it failes for numbers like 0x12345678. Also, is there please anything like the C/C++ sscanf function?

 

Thanks for replies

  • Leaders
Posted

To parse a hex number, you must first manually remove the "0x" from the beginning. Then you can use the Integer.Parse() function.

 

Integer.Parse(MyString, Globalization.NumberStyles.HexNumber)

 

The Integer.ToString() function has an overload that allows you to specify formats. You can use either the uppercase hex format specifier ("X", yields "0123456789ABCDEF") or the lower case hex format specifier ("x", yields "0123456789abcdef").

 

MessageBox.Show(MyInt.ToString("X"))

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...