I am trying to convert a Decimal to Hex as a string. I’ve looked all over for a solution to this, but all I can find is Int or long to Hex. When using the code below I receive a “Format specifier was invalid” error.
Decimal decValue = 18446744073709551615
string hexValue = decValue.ToString("X");
I’ve also looked into converting the decimal to a byte array and then converting to Hex, but I’m coming up short on that also.
Since you’re using .NET 3.5, how about IntX which will work for .NET 2.0+?
For .NET 4.0+ use
System.Numerics(remember to includeSystem.Numerics.dll)Of course this ignores any portion that is non-integer.