This is a mirror of official site: http://jasper-net.blogspot.com/

Working with BigInteger in .NET 4.0

| Tuesday, June 28, 2011
One of the interesting feature that is added with .NET 4.0 is the support of BigInteger. Big numbers are needed when a number cannot be held with any of the existing data types available with .NET framework.
Long has the highest value of 9,223,372,036,854,775,807 which is 0x7FFFFFFFFFFFFFFF in hexadecimal. This is the highest value of a variable which you can store in .NET. Or rather you can say UInt64 to store the highest value of 18,446,744,073,709,551,615 if you don’t need negatives. But this is not actually sufficient when dealing with certain situations like dealing with yearly analytical reports, statistical data etc.
BigInteger is a new type(struct) introduced in .NET 4.0 which deals with the situation and can store any value. To use it you need to add System.Numarics.dll.

For instance :

BigInteger binteger = new BigInteger(3824783785434543);
Console.WriteLine(binteger);

Here in the constructor I have specified the value with which the binteger is to be initialized. You can also use assignment operator and any operators with this object.

BigInteger binteger = 3824783785434543;
Console.WriteLine(binteger);
Console.WriteLine(binteger > 32948454);
Console.Read();


Read more: Daily .Net Tips
QR: https://chart.googleapis.com/chart?chs=80x80&cht=qr&choe=UTF-8&chl=http://dailydotnettips.com/2011/06/27/working-with-biginteger-in-net-4-0/

Posted via email from Jasper-net

0 comments: