CIS 162

Lab 12

Fall 2018

Big Integers

Regular Java integers (i.e., ints) take up 32 bits of memory and, therefore, can hold only integers between -2,147,483,648 and 2,147,483,647. Java integers are only 32 bits because, at the time Java was designed, most computers were build to operate on at most 32 bits at one time. (Today, 64-bit machines are most common.) Such 32- and 64-bit operations happen very quickly in hardware. Storing and operating on larger numbers must be done using software.

Today, you are going to implement your own version of Java's BigInteger class. This class will allow you to store, add, multiply, compare, and print arbitrarily large integers. One common use of Java's BigInteger class is to handle the very large prime numbers used in cryptography.

In order to store a BigInteger in Java, you must represent it using a group of "smaller" variables. For this lab, you must use an array of integers to store your BigInteger Here are two ways you can use your array:

Writing BigInteger

Begin by cloning https://github.com/KurmasGVSU/BigIntLab.git (or, by creating a new project and adding MyBigInteger.java and MyBigIntegerTest.java to it). Implement and test the methods in the order listed below. This lab will be much easier to write and debug if you follow the directions. Trust me. To reduce complexity, your implementation will (1) handle only positive integers and (2) assume that all BigIntegers have 1024 characters (including leading zeros, if necessary). Testing MyBigInteger Test your MyBigInteger class using MyBigIntegerTest.java. Pay attention to how each method is tested, what test cases are chosen, and what integers are chosen for each tests.

Submisson

Demonstrate to the instructor that your test script runs correctly. Then submit a printout of the code.

For More practice

Here are some exercises that will help you prepare for the Final Exam:

Updated Sunday, 11 November 2018, 5:18 PM

W3c Validation