How to convert a gi-normous integer (in string format) to hex format? (C#)

Posted by eviljack on Stack Overflow See other posts from Stack Overflow or by eviljack
Published on 2010-04-16T12:09:59Z Indexed on 2010/04/16 12:13 UTC
Read the original article Hit count: 291

Filed under:
|
|
|

Given a potentially huge integer value (in c# string format), I want to be able to generate it's hex equivalent. Normal methods don't apply here as we are talking arbitrarily large numbers, 50 digits or more. The techniques I've seen which use a technique like this:

// Store integer 182
int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);

won't work because the integer to convert is too large.

For example I need to be able to convert a string like this:

843370923007003347112437570992242323

to it's hex equivalent.

these don't work:

http://stackoverflow.com/questions/1139957/c-convert-int-to-hex-and-back-again http://stackoverflow.com/questions/74148/how-to-convert-numbers-between-hex-and-decimal-in-c

© Stack Overflow or respective owner

Related posts about c#

Related posts about hex