Convert Type Decimal to Hex (string) in .NET 3.5
c#
Solution
Since you're using .NET 3.5, how about IntX which will work for .NET 2.0+?
var intx = new Oyster.Math.IntX(decValue.ToString());
intx.ToString(16);
For .NET 4.0+ use `System.Numerics` (remember to include `System.Numerics.dll`)
Decimal decValue = 18446744073709551615;
var bigValue = new BigInteger(decValue);
bigValue.ToString("X");
Of course this ignores any portion that is non-integer.
Problem
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.