Click here to Skip to main content
15,888,170 members
Articles / Programming Languages / Visual Basic 10
Tip/Trick

HugeInt - N Digit Arithmetic Class

Rate me:
Please Sign up or sign in to vote.
4.86/5 (7 votes)
10 Jun 2010CPOL 10.4K   146   3  
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --