-
January 7th, 2004, 08:33 AM
#1
Convert int to Hex?
Hi
I simply want to convert an int into a hex value and assign it to a string
int i = 64;
string hexValue;
In the example above I want to convert i into a Hex and assign it to hexValue?
Should be simple but Im having some difficulty doing it. Any help appreciated
Many thanks
-
January 7th, 2004, 01:21 PM
#2
how about this?
string str = System.Convert.ToString(integer, 16);
JJ
-
January 7th, 2004, 06:19 PM
#3
C# / vb.net has a great in-built namespace called System.URI , here's a quick example ...
Code:
string str = System.Uri.HexEscape((char)64);
MessageBox.Show(str); // this will show as %40 ( which is the way hex would show in web urls )
// to show without the % , the following line would apply . . .
MessageBox.Show(str.Substring(1));
string Signature = Censored;
-
January 8th, 2004, 06:10 AM
#4
Thanks for the comments
string str = System.Convert.ToString(integer, 16); - I couldnt get this to work as it gave me the wrong Hex value for the int I wanted to change for some reason
I got
string str = System.Uri.HexEscape((char)64);
to work fine which is great, Im surprised its not that obvious to change an int to a hex
Thanks again for the comments
Keith
-
January 8th, 2004, 06:21 AM
#5
Actually this code only works for char up to 255 if I entered anything above that it throws an exception.
string str = System.Uri.HexEscape((char)12625); //This does not work for example
Is there anything else that I could do to just change an int to a Hex value
-
January 8th, 2004, 06:58 AM
#6
Figured it out
String xyz = 12625.ToString("X");
Thanks again
Keith
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|