Cryptography Reference
In-Depth Information
(c)
FIGURE 2.4
(continued)
Having an Int class is a very valuable tool, for it frees us from the boundaries placed on
us by the primitive integer data types of most computer languages. A Java int, for example,
is only 4 bytes, which is not nearly large enough for the numbers we will need to handle in
this topic. However, the cost of this freedom is decreased performance, and as a result large
integer packages are usually very carefully designed and optimized to yield the maximum
benefit. The Int class as we have designed it here is in fact rather poor, but it is neverthe-
less a good introduction for someone who has never attempted the feat before. In the exer-
cises we will discuss how to produce a much better Int class.
2.4
THE JAVA BIGINTEGER CLASS
Java provides a BigInteger class with the same functionality that we have given our Int
class, and more. It is optimized for speed, and we will use it for further development. Rewrit-
ing programs for the Int class and then comparing their performances to the BigInteger class
will make interesting exercises, and you are invited to do this.
2.5
CONSTRUCTORS
A partial list of the BigInteger constructors and methods follows:
public BigInteger(byte B[]) throws NumberFormatException
complement representation
of a signed integer into a BigInteger (see Figure 2.5). The input array is assumed to be big-
endian; that is, the most significant byte is in the [0] position. The most significant bit of the
most significant byte is the sign bit. The array must contain at least one byte or a Number-
FormatException will be thrown.
This constructor translates a byte array containing the two
'
s
-
public BigInteger(int signum, byte magnitude[]) throws
NumberFormatException
Search WWH ::




Custom Search