Link to home
Start Free TrialLog in
Avatar of dominicwong
dominicwong

asked on

How to convert a 39-decimal characters into hex in c#

Hi experts
I've a string representation of a 39-characters long decimal integer.
I need to convert this into hex format in C#.
eg. 340282366920938463463374607431768211455 (39 characters)
      -> ffffffffffffffffffffffffffffffff (32 characters)

By the same token, I need to be able to reverse the operation from hex to decimal.

I am using C# .NET 3.5 which hasn't got BigInteger.

Any advice please.  Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of QuinnDex
QuinnDex

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There is a BigInteger. It is "hidden" in the System.Numerics namespace, available after referencing the dll by the same name.

If you can get a string representation of your value, the following will do the job:

BigInteger bigInt = BigInteger.Parse ( "340282366920938463463374607431768211455" );
string bigHex = bigInt.ToString ("X");
bigInt = BigInteger.Parse ( bigHex, System.Globalization.NumberStyles.HexNumber );

Otherwise, give a look at the BigInteger Structure in the documentation, it is quite exhaustive.
Avatar of QuinnDex
QuinnDex

BigInteger is part of .net 4, OP is working with .net 3.5
Avatar of dominicwong

ASKER

Thanks QuinnDex. That works like a charm, and is exactly what I need.

Thanks also to JamesBurger for your help.