0

I mean how can I convert my hexadecimal values to biginteger ?

for example i use this :

string value="A1";
BigInteger bi=new BigInteger(value,16);

bi =161; this is true? So how can I convert back it to "A1"?

thanks..

CompEng
  • 7,161
  • 16
  • 68
  • 122
  • 2
    Little bit confused which BigInteger you use that has this constructor – meandmycode May 20 '12 at 19:43
  • 1
    @ErsinGülbahar - The answers you have gotten are about `System.Numerics.BigInteger` that is in the .NET 4.0 framework library. Are you using a different one? If so, which one (links please). – Oded May 20 '12 at 19:52
  • In your [last question](http://stackoverflow.com/questions/10624815/how-can-i-use-bigint-with-c) 4 answers recommended using `BigInteger` from the .NET framework library. Why didn't you use that? – Oded May 20 '12 at 20:19
  • @meandmycode The Java class BigInteger has such a constructor. – user1938742 Oct 14 '15 at 08:13

3 Answers3

2

String.Format supports this:

String.Format("0:x", 161);

Working example:

        string value="A1";
        BigInteger bi = BigInteger.Parse(value, NumberStyles.HexNumber);
        string newVal = string.Format("{0:x}", bi);
        //newVal is a1

UPDATE: The above suggestion is valid for the BigInteger implementation in the System.Numerics namespace of .NET

Pencho Ilchev
  • 3,201
  • 18
  • 21
1

To convert back the BigInteger to hexadecimal string you can do in this way :

string value= bi.ToString("X");
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
aleroot
  • 71,077
  • 30
  • 176
  • 213
  • it is error me. like this : The best overloaded method match for 'BigInteger.ToString(int)' has some invalid argument – CompEng May 20 '12 at 19:45
1

ToString is overridden in BigInteger:

bi.ToString("X")
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • it is error me. like this : The best overloaded method match for 'BigInteger.ToString(int)' has some invalid arguments – CompEng May 20 '12 at 19:42
  • @ErsinGülbahar - Where are you finding an override that takes an `int`? Post the _exact_ code you are trying. Also - stop posting the exact same comment to everyone who answered. It is annoying. – Oded May 20 '12 at 19:43