Comp Sci Computer programing - making new data types for integers java/c

AI Thread Summary
To create a new data type in Java that can handle larger integers than standard types, one approach is to implement arbitrary precision arithmetic. This involves using base systems like 65536 or 4294967296 for convenience. The implementation would require managing multiple "words" of data, utilizing bitwise operations to handle overflow when calculations exceed the capacity of lower words. Since the use of Java's BigInteger class is not permitted for the assignment, a custom solution must be developed. Understanding how to perform these calculations manually, similar to pen and paper methods, is essential for success.
vorcil
Messages
395
Reaction score
0
How would I make a new data type that would hold larger numbers than ones that we can currently use?

for example I need a data type that can handle calculations from large factorials
e.g
200!, = 200*199*198*197 ......
it's a really large number and can't be saved in ints/doubles/longs ect...
so i need to make a new data type,

how would I do this?

I know both java and C, but would prefer it if the help was done in java

thanks
 
Physics news on Phys.org
google: arbitrary precision arithmetic

plus java has a BigInteger class already.
 
thanks,

another note, I'm doing an assignment
and have been told that I'm not allowed to use biginteger
 
You already know how -- you do it with pen and paper all the time.

However, base 65536 or base 4294967296 is probably more convenient than base 10.


qbert gave you a buzzword for searching. Another one is "multi-precision arithmetic".
 
you will need to use the bit operators( | &) and keep track of the bit pushed off the the lower words and add it to the higher words
 

Similar threads

Replies
1
Views
1K
Replies
12
Views
2K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
2
Views
4K
Replies
3
Views
1K
Replies
1
Views
2K
Back
Top