created: 02/20/2018

CHAPTER 56 — Big Integer

Sometimes you need to compute with very large numbers. The primitive type `int` is only 32 bits, which limits the size of integers to plus-or-minus 231, roughly plus-or-minus two billion. The primitive type `long` is 64 bits, but sometimes even this is too limited. Especially in cryptography and other number theory applications you need integers of unlimited size.

This chapter discusses the class `BigInteger` which implements arbitrary-precision integers. This means integers, both positive and negative, can be of any magnitude.

`BigInteger`s are not required for the AP Java test.

Chapter Topics:

• BigInteger
• toString
• multiply, divide
• remainder, mod
• equals, compareTo
• pow

QUESTION 1:

(Trick Question: ) What is the output of the following fragment?

```if ( 1_000_000_000 + 2_000_000_000 > 0 )
System.out.println("Obviously True");
else
System.out.println("What???");

```

Note: the literals in the `if` statement are correct. In Java version 7 and later, underscores can be used inside numeric literals to make reading easier. Don't put them at the start or end of a literal, though.