Mega Code Archive

 
Categories / C# / Data Types
 

Tries to convert string in style and culture-specific format to BigInteger

using System; using System.Globalization; using System.Numerics; public class Example {    public static void Main()    {       string[] hexStrings = { "80", "E293", "F9A2FF", "FFFFFFFF",                                "0080", "00E293", "00F9A2FF", "00FFFFFFFF" };       BigInteger number = BigInteger.Zero;       foreach (string hexString in hexStrings)       {          if (BigInteger.TryParse(hexString, NumberStyles.AllowHexSpecifier,                                  null, out number))             Console.WriteLine("Converted 0x{0} to {1}.", hexString, number);          else             Console.WriteLine("Cannot convert '{0}' to a BigInteger.", hexString);       }    } }