Here are some simple functions that show how to convert HEX string values into various C# numeric data types (and vice versa):
using System.Globalization;
long hextolong(string hexValue)
{
return long.Parse(hexValue, NumberStyles.AllowHexSpecifier);
}
int hextoint(string hexValue)
{
return int.Parse(hexValue, NumberStyles.AllowHexSpecifier);
}
string inttohex( int intValue )
{
return intValue.ToString("X");
}
string longtohex( long longValue )
{
return longValue.ToString("X");
}
If you need zero padding for your HEX values you can use this notation:
To produce 2 character zero padding (like 01 or 0A) use: