How to use BigInteger numbers in C#

No.of Views3236
Bookmarked0 times
Downloads 
Votes0
By  kirtan007   On  22 Jun 2010 09:06:10
Tag : CSharp , CSharp4.0
In this article I will show you about using BigInteger Class of the framework 4.0.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article I will show you about using BigInteger Class of the framework 4.0 that can perform arithmetic operations on integer values that can exceed the size of default numeric types. For example even largest one Int64.MaxValue.Numeric values in .net framework have some max and min values according to their memory allocation. BigInteger can deal with bigger integers such like 91389681247993671255432112000000 that is not performable by default data types.

Technology

C#, .NET 4.0

Implementation

Suppose we want to do sum of 2 huge numbers that are bigger then Int64. We can perform the operation by BigInteger class.

First of all you need to import namespace.

Image Loading
using System.Numerics;

Here I am showing screen shot of application. 

Image Loading

You can perform basic operation like below code.

BigInteger bigInt1 = new BigInteger(123456789101112131415);
BigInteger bigInt2 = new BigInteger(123456789632312211212);
BigInteger Total = BigInteger.Add(bigInt1,bigInt2);
// Show the ResultTextBox3.Text = Total.ToString(); 

 I am listing some methods of BigInteger class that can be useful for computing .

BigInteger.Add()
BigInteger.Multiply()
BigInteger.Parse();
BigInteger.Divide();
BigInteger.Subtract();

Many more methods are available that are useful for arithmatic operations.

Conclusion

We have just seen in this article how to deal with BigInteger Class of .net framework 4.0 to perform arithmetic operations on values that are bigger than default data types provided by .net framework.

Sample Project Source

Download source files -41 kb

 
Sign Up to vote for this article
 
About Author
 
kirtan007
Occupation-
Company-
Member Type-Senior
Location-Not Provided
Joined date-02 Jul 2009
Home Page-http://kirtan.uni.cc
Blog Page-
He completed his Bachelor of Computer Application from Gujarat University 2009 .He is doing Master of Computer Application from Gujarat Technological University right now .. His area of Interests are Web Hacking , C# .net Windows form ,asp.net , WPF ,Silverlight ,SQL Server and Some PHP.
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top
</