1

I have a string which contains a big hexadecimal number, something like this :

string hexa = "292145F2E92145E6B92FAA6A95FF7E6B92145FAA6A22DE192145FAA696043F457306A"; 

I just want to transform this hexa string in a BigInteger variable (WITHOUT modifying the value of the string) to use it after.

Something like this :

BigInteger blabla = new BigInteger(hexa);

I just want the same string, but in BigInteger variable

General Grievance
  • 4,555
  • 31
  • 31
  • 45
hyspo
  • 29
  • 5
  • Parsing `BigInteger` works just like the other integer types in C#. See duplicates. You may also want to read the answer to [this question](https://stackoverflow.com/questions/26871079/what-is-the-proper-way-to-construct-a-biginteger-from-an-implied-unsigned-hexedi) – Peter Duniho Nov 03 '20 at 19:40

2 Answers2

6

You can BigInteger.Parse it with AllowHexSpecifier flag given:

using System.Globalization;

...

string hexa = "292145F2E92145E6B92FAA6A95FF7E6B92145FAA6A22DE192145FAA696043F457306A";
var bigInt = BigInteger.Parse(hexa, NumberStyles.AllowHexSpecifier);
Matthew
  • 24,703
  • 9
  • 76
  • 110
nkrivenko
  • 1,231
  • 3
  • 14
  • 23
4

Try the BigInteger.Parse static method, and pass either the NumberStyles.HexNumber or NumberStyles.AllowHexSpecifier flag.

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720