Reputation: 6226
How would I convert a string that represents an integer like "4322566" to a hex string?
Upvotes: 9
Views: 2871
Reputation: 25024
int temp = 0;
string hexOut = string.Empty;
if(int.TryParse(yourIntString, out temp))
{
hexOut = temp.ToString("X");
}
To handle larger numbers per your comment, written as a method
public static string ConvertToHexString(string intText)
{
long temp = 0;
string hexOut = string.Empty;
if(long.TryParse(intText, out temp))
{
hexOut = temp.ToString("X");
}
return hexOut;
}
Upvotes: 2
Reputation: 22770
Try
int otherVar= int.Parse(hexstring ,
System.Globalization.NumberStyles.HexNumber);
Upvotes: 0