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

In summary, to create a new data type that can handle larger numbers, one can use arbitrary precision arithmetic or multi-precision arithmetic. In Java, this can be achieved using the BigInteger class or by keeping track of bits using bit operators. One may also consider using a different base, such as base 65536 or base 4294967296, for convenience. However, it is important to note that the use of such a data type may not be allowed in certain assignments.
  • #1
vorcil
398
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
  • #2
google: arbitrary precision arithmetic

plus java has a BigInteger class already.
 
  • #3
thanks,

another note, I'm doing an assignment
and have been told that I'm not allowed to use biginteger
 
  • #4
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".
 
  • #5
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
 

Related to Computer programing - making new data types for integers java/c

1. What is a data type in Java?

A data type in Java is a classification of data that determines the type of values that can be stored and the operations that can be performed on those values. It specifies the size, format, and range of values that can be stored in a variable.

2. What is the difference between primitive and non-primitive data types in Java?

Primitive data types are basic data types that are built into the Java language, such as int, boolean, and char. Non-primitive data types are created by the programmer and are typically objects, such as String or Arrays.

3. How do you declare a new data type for integers in Java?

To declare a new data type for integers in Java, you can use the keyword "int" followed by the name of your data type. For example: "int myInteger;"

4. Can you create a custom data type for integers in Java?

Yes, you can create a custom data type for integers in Java by using the "class" keyword and defining your own class with its own properties and methods.

5. How do you use a custom data type for integers in Java?

To use a custom data type for integers in Java, you need to first instantiate an object of that class and then use the object to access its properties and methods. For example: "MyCustomInteger myInteger = new MyCustomInteger();"

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
Back
Top