Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

HugeInt - N Digit Arithmetic Class

0.00/5 (No votes)
10 Jun 2010 1  
A class for N-Digit Arithmetic

Introduction


HugeInt Class is like any Integer Class(only +,-,*,^ are supported) but can hold any number of digits.


Using the Code


HugeInt can be used like this:


VB
Dim int1 as New HugeInt.HugeInt("2")
Dim int2 as New HugeInt.HugeInt("4096")
MsgBox(int1^int2)
MsgBox(CStr(int1*int2).Length)

Keep in mind that this class is not designed for high-speed arithmetic. My aim was to develop logic in basic n-digit arithmetic.


A Factorial function or Permute or Combine function can also be included. But I thought the basic functions would be enough for logic.


This class will be very useful for computations of Combinations or Permutations or 1000!(factorials) or big exponents(10^10000). Every digit of the given integer is accurate.


Internally, it uses a string array for the digits. So the precision is upto the nth digit.


Points of Interest


First, I tried to convert an N-Digit number to Binary format. But I couldn't develop a good method other than dividing and getting the remainder(if there is a good method, please let me know.)


A Case-By-Case Analysis of what our human brain does for various types of subtraction(borrows, first digit etc.) was interesting and I learnt how complex the brain is!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here