You were not able to use the conversion base. There is also a problem because this number does not fit into a int
, you must use a long
( Convert.ToInt64()
) to perform the conversion.
using System;
using System.Numerics;
using System.Globalization;
public class Program {
public static void Main() {
var hex = "E365A931A000000";
Console.WriteLine(Convert.ToInt64(hex, 16));
hex = "E365A931";
Console.WriteLine(Convert.ToInt32(hex, 16));
hex = "E365A931A000000000";
Console.WriteLine(BigInteger.Parse(hex, NumberStyles.HexNumber));
}
}
See working on dotNetFiddle .
I showed an example with a smaller number to fit in int
. And a conversion that accommodates numbers of any size. You should evaluate whether it's worth using BigInteger
.