public final class BigNumber extends Object
BigNumber class encapsulates an unsigned number whose
value is represented in internal hexadecimal format using an implementation
specific maximum number of bytes. This class supports the BCD (binary coded
decimal) format for I/O.| Modifier and Type | Field and Description |
|---|---|
static byte |
FORMAT_BCD
Constant to indicate a BCD (binary coded decimal) data format.
|
static byte |
FORMAT_HEX
Constant to indicate a hexadecimal (simple binary) data format.
|
| Constructor and Description |
|---|
BigNumber(short maxBytes)
Creates a BigNumber instance with initial value 0.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
Increments the internal big number by the specified operand value
|
byte |
compareTo(BigNumber operand)
Compares the internal big number against the specified operand.
|
byte |
compareTo(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
Compares the internal big number against the specified operand.
|
short |
getByteLength(byte arrayFormat)
Returns the number of bytes required to represent the big number using
the desired format
|
static short |
getMaxBytesSupported()
This method returns the byte length of the hex array that can store the
biggest BigNumber supported.
|
void |
init(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
Initializes the big number using the input data
|
void |
multiply(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
Multiplies the internal big number by the specified operand value
|
void |
reset()
Resets the big number to 0
|
void |
setMaximum(byte[] maxValue,
short bOff,
short bLen,
byte arrayFormat)
Sets the maximum value that the BigNumber may contain.
|
void |
subtract(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
Decrements the internal big number by the specified operand value
|
void |
toBytes(byte[] outBuf,
short bOff,
short numBytes,
byte arrayFormat)
Writes the internal big number out in the desired format.
|
public static final byte FORMAT_BCD
public static final byte FORMAT_HEX
public BigNumber(short maxBytes)
maxBytes - maximum number of bytes needed in the hexadecimal format for
the largest unsigned big number. For example, maxBytes = 2
allows a big number representation range 0-65535.ArithmeticException - if maxBytes is 0, negative or larger than the supported
maximumpublic void setMaximum(byte[] maxValue,
short bOff,
short bLen,
byte arrayFormat)
Note:
maxValue - input byte arraybOff - offset within input byte array containing first byte (the high
order byte)bLen - byte length of input dataarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.NullPointerException - if maxValue is nullArrayIndexOutOfBoundsException - if accessing the input array would cause access of data
outside array bounds or if bLen is negativeArithmeticException - for the following conditions:
arrayFormat parameter
bLen is 0
arrayFormat is not one of the
FORMAT_ constants.
public static short getMaxBytesSupported()
public void init(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
throws NullPointerException,
ArrayIndexOutOfBoundsException,
ArithmeticException
bArray - input byte arraybOff - offset within byte array containing first byte (the high order
byte)bLen - byte length of input dataarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.ArrayIndexOutOfBoundsException - if accessing the input array would cause access outside
array bounds or if bLen is negativeNullPointerException - if bArray is nullArithmeticException - for the following conditions:
arrayFormat parameter
bLen is 0
arrayFormat is not one of the
FORMAT_ constants.
public void add(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
throws NullPointerException,
ArrayIndexOutOfBoundsException,
ArithmeticException
bArray - input byte arraybOff - offset within input byte array containing first byte (the high
order byte)bLen - byte length of input dataarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.ArrayIndexOutOfBoundsException - if accessing the input array would cause access of data
outside array bounds or if bLen is negativeNullPointerException - if bArray is nullArithmeticException - for the following conditions:
arrayFormat parameter
bLen is 0
arrayFormat is not one of the
FORMAT_ constants
public void subtract(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
throws ArithmeticException
bArray - input byte arraybOff - offset within input byte array containing first byte (the high
order byte)bLen - byte length of input dataarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.ArrayIndexOutOfBoundsException - if accessing the input array would cause access of data
outside array bounds or if bLen is negativeNullPointerException - if bArray is nullArithmeticException - for the following conditions:
arrayFormat parameter
bLen is 0
arrayFormat is not one of the
FORMAT_ constants.
public void multiply(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
throws ArithmeticException
bArray - input byte arraybOff - offset within input byte array containing first byte (the high
order byte)bLen - byte length of input dataarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.ArrayIndexOutOfBoundsException - if accessing the input array would cause access of data
outside array bounds or if bLen is negativeNullPointerException - if bArray is nullArithmeticException - for the following conditions:
arrayFormat parameter
bLen is 0
arrayFormat is not one of the
FORMAT_ constants.
public byte compareTo(BigNumber operand)
byte result, this method sets the
result in an internal state which can be rechecked using assertion methods
of the SensitiveResult class,
if supported by the platform.operand - contains the BigNumber operand0 if equal-1 if the internal big number is less than
the specified operand1 if the internal big number is greater than
the specified operandNullPointerException - if operand is nullpublic byte compareTo(byte[] bArray,
short bOff,
short bLen,
byte arrayFormat)
byte result, this method sets the
result in an internal state which can be rechecked using assertion methods
of the SensitiveResult class,
if supported by the platform.bArray - input byte arraybOff - offset within input byte array containing first byte (the high
order byte)bLen - byte length of input dataarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.0 if equal-1 if the internal big number is less than
the specified operand1 if the internal big number is greater than
the specified operandArrayIndexOutOfBoundsException - if accessing the input array would cause access of data
outside array bounds or if bLen is negativeNullPointerException - if bArray is nullArithmeticException - for the following conditions:
arrayFormat parameter
bLen is 0
arrayFormat is not one of the
FORMAT_ constants.
public void toBytes(byte[] outBuf,
short bOff,
short numBytes,
byte arrayFormat)
throws ArrayIndexOutOfBoundsException,
NullPointerException
outBuf - output byte arraybOff - offset within byte array containing first byte (the high order
byte)numBytes - number of output bytes requiredarrayFormat - indicates the format of the input data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.ArrayIndexOutOfBoundsException - if accessing the output array would cause access of data
outside array bounds or if numBytes is
negativeNullPointerException - if outBuf is nullArithmeticException - for the following conditions:
numBytes is not sufficient to
represent the big number in the desired format
numBytes is 0
arrayFormat is not one of the
FORMAT_ constants.
public short getByteLength(byte arrayFormat)
arrayFormat - indicates the format of the output data. Valid codes listed in
FORMAT_* constants, for example
FORMAT_BCD.ArithmeticException - if arrayFormat is not one of the FORMAT_
constants.public void reset()
Copyright © 1998, 2015, Oracle and/or its affiliates. All rights reserved.