index > Installing and Registering Visual Studio Express Editions > Handling large integers

Handling large integers

Hi, I understand that 32bit processors can only natively handle integers that are of a magnitude less than 4,294,967,296. Exactly what happens if I was to write a C# program that tried to mutiply/divide numbers larger than that? Will the compiler take care of the issue for me or will I be unable to do that without writing complex logic? I'm new to application programming (all I know is PHP, MySQL, XML, XHTML and CSS but I've been working on learning C#) so I'm not sure what will happen. I'm guessing the compiler will take care of it for me but I want to know that prior to writing the application.``
Shining Arcanine
Rather than simply using a int (Int32), you can actually use a long (Int64) which can handle integers up to 9,223,372,036,854,775,807.

If you write operations that cause numbers to be greater than their holding type, one of two things will happen:

1. If 'Check for arithmetric overflow/underflow' is checked (Project Properties -> Build -> Advanced) or if the statement is within a checked statement than an OverflowException will be thrown.

2. If the above option is unchecked or if the statement is within an unchecked statement than no exception will be thrown and the operation will overflow/underflow.

For example, in the following statements the first will throw an OverflowException, whereas in the second value will contain the lowest possible value that an long (Int64) can contain (-9,223,372,036,854,775,808). The third statement will depend on whether the above option is checked or not:

1. long value = checked(Int64.MaxValue + 1);

2. long value = unchecked(Int64.MaxValue + 1);

3. long value = Int64.MaxValue + 1;



VS Code Analysis Team | My Blog: http://davidkean.net | FxCop Blog: http://blogs.msdn.com/FxCop
David M. Kean
I'd like to process numbers approximately 10^(10^10) digits long so unfortunately Int64 is too small for the numbers I'd like to process. So far I've been using Double but it is also too small for what I'd like to do.
Shining Arcanine
A double will store numbers that large, but only to a certain number of significant figures. To store a number precisely you need enough bits to store the number in binary. So 10^10^10 is 1x10^100. To figure how many bits you need, see what power of two is bigger than the number, fiddling with calculator I get
2^333 = 1.7*10^100

so you would need 333 bits to fit integers of this magnitude, ( int333 ).
There are no default types for this, so if you want precision you will have to make a big number class, and do all the methods by hand. Something like this:
http://www.cs.sunysb.edu/~skiena/392/lectures/week5/



jo0ls
jo0ls, thanks for the information. The magnitude I need to be able to calculate numbers at actually was 10^10000000000 (hence my use of parenthesises) so I'll need Int16777216. Writing all of the methods for it by hand will be fun, especially with relatively little C# experience and knowledge. I'll get started on it tomorrow. Thanks again.
Shining Arcanine
reply 5

You can use google to search for other answers

 

More Articles

• big BUG? ActiveX, backgroundworker1
• Cannot Uninstall VWD Express
• Installing over VS 2005 Beta 2
• Master-detail from two tables
• C# Express Edition Installation...
• SQL database
• resize web report viewer control on size to report
• Help converting Function to C#
• Calendar Control and Database Connection
• "unknown error" when starting visual web developer 2005...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• where are the databases?
• Need Help with Visual Basic 2005 Exp. Re
• Instalation Problem -C# Express
• registration thank you email suggestion
• System.Runtime.Serialization.Serializati
• Cannot uninstall MSN Express Library 200
• Linker errors when building samples...
• VbExpress DataGridView Header BackColor
• VB 2005 Express - problem with confirmat
• Which Data Type??
• I am still having problems with intallin
• Curley Crazy {
• Does DbCombo V4.1 work in Microsoft Visu
• Problem when using SerialPort.GetPortNames
• using VB on 64bit machines

Hot Articles

• Error 1402 Could not open Key?
• visual basic templates
• Trying to catch the MSDN Express
• Cannot find MSDN Express Library and SQL
• Dotfuscator in Express ?
• Class 'CLSID_CorSymWriter'
• Registration clarification?
• problems Registering for Visual Web deve
• bewildered
• It endless read my drive A ?
• License and time limit
• Service Pack packaging for SQL Server 20
• VB- and VC#-EE on one machine
• Searching for e-books
• Publish tab for Project displayed with e

Recommend Articles

• Reports
• can i use the Express Edition to control
• installing on more then one machine?
• The page cannot be displayed
• AspNetAccessProvider missing from Vis.we
• XML/SOAP based webservice Help
• Visual Studio and Express on the same co
• Problem Installing Beta 2
• SQL Express Manager, Cannot Connect
• c# program incl .net framework 2 dlls
• Work around for SP2 to be installed
• VB 2005 Express - problem with confirmat
• Registering....
• Registration process reveals information
• Failed installation of Microsoft SQL Ser