C # Convert number greater than Int64 to HexaDecimal

I am trying to convert a large number (ex: 9407524828459565063) to hexadecimal (ex: 828E3DFD00000000) in C #.

The problem is that the number is greater than the Int64 max value.

I searched everywhere and could not find a working solution.

Any help here?

Thank.

+3
source share
3 answers

I would use the System.Numerics.BigInteger class for this. The exact solution depends on the format in which you have this number: string, double, other.

If line ( s):

var bigInt = BigInteger.Parse(s);
var hexString = bigInt.ToString("x");

If double ( d):

var bigInt = new BigInteger(d);
var hexString = bigInt.ToString("x");

... etc.

+7
source

May be:

BigInteger b = 9407524828459565063;
var hex = b.ToString("X2");

Or

ulong l = 9407524828459565063;
var hex = l.ToString("X2");
+3
source

.NET 4.0, BigInteger:

http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx

  BigInteger bi = new BigInteger();
  bi = 9407524828459565063;
  string bix = bi.ToString("X");
+2

All Articles