nova47

October 9th, 2009, 04:56 AM

For one of my classes I am supposed to write an implementation of unsigned in Java without using either the BigInteger or BigDecimal classes. The challenge is as follows:

--------------------------------------------------------------

A natural number is a number greater than or equal to 0. Java does not provide a primitive type that corresponds to natural numbers: only boolean and char are unsigned and neither provides very many distinct values (2 in the case of boolean and 65,536 in the case of char).

Your task is to implement a class that supports arbitrary-sized natural numbers (that is, limited only by memory availability for the JVM, not by some constant limit defined a priori by your class). This class is similar, at least in intent, to the Natural component from the Resolve/C++ component catalog.

Note that Java does provide, as part of the standard libraries, various implementations of arbitrary-sized numbers (e.g., BigInteger and BigDecimal). For the purpose of this lab, however, you are asked not to use the these classes in your own solution.

--------------------------------------------------------------

I'm not looking to cheat but does anyone have any ideas on how to approach the problem? I'm just looking for a point in the right direction. I feel like this is a bit manipulation problem but I don't know how.

--------------------------------------------------------------

A natural number is a number greater than or equal to 0. Java does not provide a primitive type that corresponds to natural numbers: only boolean and char are unsigned and neither provides very many distinct values (2 in the case of boolean and 65,536 in the case of char).

Your task is to implement a class that supports arbitrary-sized natural numbers (that is, limited only by memory availability for the JVM, not by some constant limit defined a priori by your class). This class is similar, at least in intent, to the Natural component from the Resolve/C++ component catalog.

Note that Java does provide, as part of the standard libraries, various implementations of arbitrary-sized numbers (e.g., BigInteger and BigDecimal). For the purpose of this lab, however, you are asked not to use the these classes in your own solution.

--------------------------------------------------------------

I'm not looking to cheat but does anyone have any ideas on how to approach the problem? I'm just looking for a point in the right direction. I feel like this is a bit manipulation problem but I don't know how.