Tweet
SIGN UP
MEMBER LOGIN:
TECHNOLOGIES
.NET 4.5
.NET Remoting in C#
Active Directory C#
ADO.NET in C#
AJAX in C#
Algorithms in C#
Android Programming
Articles C#
ASP, JavaScript, CSS
ASP.NET Controls in C#
ASP.NET MVC with C#
ASP.NET Programming
BizTalk Server
C# Assemblies
C# Language
C# Tutorials
C, C++, MFC
Career Advice
Chapters
Cloud Computing
COBOL.NET
Coding Best Practices
COM Interop
Compact Framework
Cryptography C#
Crystal Reports C#
Current Affairs
Custom Controls C#
Databases & DBA
Deployment
Design & Architecture
DirectX C#
Enterprise Development
Error Zone
Exception Handling C#
Expression Studio
F#
Files, Directories in C#
Financial Applications
Games Programming C#
GDI+ & Graphics
Hardware
How do I
HTML 5
Internet & Web
iPhone/iPad
Java
Java and .NET
JQuery
JSP
Leadership
Learn .NET
LINQ with C#
Metro Style Apps in C#
Mobile & Embedded
MonoDevelop
MSMQ in C#
Multithreading in C#
Networking
Office Development
OOP/OOD
Operating Systems
PHP
Printing in C#
Products
Project Management
Reports using C#
Robotics & Hardware
Security in .NET
SharePoint
Silverlight with C#
Smart Devices
Speech in C#
SQL
SQL Server 2012
String in C#
Team Foundation & VSS
Testing
Visual Basic .NET
Visual C#
Visual Studio .NET
Visual Studio 11
Visual Studio 2010
VS LightSwitch 2011
WCF with C#
Web Forms C#
Web Services in C#
WebForms Controls
Windows 8 in C#
Windows Controls C#
Windows Forms C#
Windows Phone in C#
Windows PowerShell
Windows Services in C#
Workflow Foundation in C#
WPF with C#
XAML with C#
XML in C#
XNA with C#
FORUMS
BLOGS
VIDEOS
INTERVIEWS
CERTIFICATIONS
DOWNLOADS
BOOKS
LINKS
NEWS
Learn .NET in 60 days – Part 1 (13 Labs)
Learn MVC (Model view controller) Step by Step ...
Learn C# Corner - Home
Using Border Radius and Gradients in CSS3: Part I
Learn C# Corner - Footer
Learn .NET and C# in 60 Days Lab13(Day 5): - C ...
iPhone 5 First Look
Samsung Galaxy Note Review
WCF - Authentication and Authorization in Ente ...
How to write a good article on C# Corner
Blog
Manipulating Huge Integers In C#
Posted by
Krishna Garad
in
Blogs
|
C# Language
on
Feb 04, 2012
In this blog we will see how to work with big integers.
Tweet
576
0
0
Introduction
In this blog we will see how to work with big integers. In lot of cases we required to manipulate the big inter numbers and finally we have only capacity of work still 19 digits by using Int64. Until .Net Framework version 3.5 we have to use only max Int64 but in .Net framework version 4.0 we got one more new struct using System.Numerics.BigInteger. Using this struct we are able to manipulate big integers, doubles, bytes and decimal values. Using biginteger we are able perform the calculations on the numbers which are more than 50 digits also.
In last cases like Int64 we if we pass more than 19 digits it's throws an error either input string too long or too short but using new struct i.e. BigInteger you can pass more than 50 also. So let's see some operations of using this new biginteger.
Example 1 :
Addition
Using biginteger you can make addition of more than 50 digits also and this biginteger struct only provide the Add method which takes two biginteger values and returns the biginteger try it like bellow.
public
BigInteger
addHugeIntegers(
BigInteger
a, BigInteger b)
{
return
BigInteger
.Add(a, b);
}
Example 2 :
Subtract
BigInteger provide the Subtract method using you can make subtraction in two huge integer values like bellow.
public
BigInteger
subtractHughIntegers(
BigInteger
a,BigInteger b)
{
return
BigInteger
.Subtract(a, b);
}
Example 3 :
Compare
Biginteger is able to compare two values also like first value is greater than or equal to or less than etc… like bellow.
public
int
Compare(
BigInteger
a,
BigInteger
b)
{
return
BigInteger
.Compare(a, b);
}
Example 4 :
EqualTo:
Biginteger is able to check the two values are equal or not equal to and return the bool true if they are equal and returns false if they are not equal like bellow.
public
bool
isEqualTo(
BigInteger
a,BigInteger b)
{
return
BigInteger
.Equals(a,b);
}
Our biginteger having more methods also which takes input as Double, Decimal and bytes also for more you can refer
MSDN
. But remind the biginteger supports only Vista SP1, 7, xp sp3 and server 2008/R2, Server 2003 Sp2 these versions of os are supported by BigInteger.
Conclusion
Using BigInteger in .Net 4.0 we are able to manipulate huge integers which may have more than 50 digits also.
share this blog :
Adding Different Class Object in..
Leverage “using” in C#
Related Blogs
ADO.NET Connection string manipulation in C#
Concatenation an integer and a string in C#
Some C# Tips
String encryption using C#
Pyramid Using C#
Disable Browser Back Button Functionality Using Pagebehind(C#)
post comment
Sponsored by
Become a Sponsor
More Blogs from this Blogger
Manipulating Huge Integers In C#
File Encoding And Decoding In .Net Using Simple IO Operations
Call Stored Procedure With In/Out Parameter In 3-Tier
Calling DataSet with Stored Procedure in 3-tier
View All
Latest Blogs
Free Ride is Over for Desktop Developers in Visual Studio 11
DotNet developers most used application/tools launching through 'Run'
80-inch Windows 8 Tablet
Data encapsulation
Option to access the Column Names in Data table
Open multiple windows in browser startup. (Multiple homepages option)
I'm Sorry
const and readonly
Address, Binding and Contract in WCF
JQuery Maxchars Plugin
View All
Sponsored by
Become a Sponsor