**javacardx.framework.math** ====Class BigNumber ==== *[[javacard:java-card-api:object|java.lang.Object]] \\ ---- public final class **BigNumber**extends [[javacard:java-card-api:Object|Object]] The 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. **Since:** 2.2.2 ---- ^ Field Summary ^^ | **static byte** | **[[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] **          Constant to indicate a BCD (binary coded decimal) data format. | | **static byte** | **[[javacard:java-card-api:BigNumber#FORMAT_HEX|FORMAT_HEX]] **          Constant to indicate a hexadecimal (simple binary) data format. |   ^ Constructor Summary ^^ | **[[javacard:java-card-api:BigNumber#BigNumber(short)|BigNumber]] **(short maxBytes)          Creates a BigNumber instance with initial value 0. |   ^ Method Summary ^^ | ** void** | **[[javacard:java-card-api:BigNumber#add(byte[], short, short, byte)|add]] **(byte[] bArray,short bOff,short bLen,byte arrayFormat)          Increments the internal big number by the specified operand value | | ** byte** | **[[javacard:java-card-api:BigNumber#compareTo(javacardx.framework.math.BigNumber)|compareTo]] **([[javacard:java-card-api:BigNumber|BigNumber]]  operand)          Compares the internal big number against the specified operand | | ** byte** | **[[javacard:java-card-api:BigNumber#compareTo(byte[], short, short, byte)|compareTo]] **(byte[] bArray,short bOff,short bLen,byte arrayFormat)          Compares the internal big number against the specified operand. | | ** short** | **[[javacard:java-card-api:BigNumber#getByteLength(byte)|getByteLength]] **(byte arrayFormat)          Returns the number of bytes required to represent the big number using the desired format | | **static short** | **[[javacard:java-card-api:BigNumber#getMaxBytesSupported()|getMaxBytesSupported]] **()          This method returns the byte length of the hex array that can store the biggest BigNumber supported. | | ** void** | **[[javacard:java-card-api:BigNumber#init(byte[], short, short, byte)|init]] **(byte[] bArray,short bOff,short bLen,byte arrayFormat)          Initializes the big number using the input data | | ** void** | **[[javacard:java-card-api:BigNumber#multiply(byte[], short, short, byte)|multiply]] **(byte[] bArray,short bOff,short bLen,byte arrayFormat)          Multiplies the internal big number by the specified operand value | | ** void** | **[[javacard:java-card-api:BigNumber#reset()|reset]] **()          Resets the big number to 0 | | ** void** | **[[javacard:java-card-api:BigNumber#setMaximum(byte[], short, short, byte)|setMaximum]] **(byte[] maxValue,short bOff,short bLen,byte arrayFormat)          Sets the maximum value that the BigNumber may contain. | | ** void** | **[[javacard:java-card-api:BigNumber#subtract(byte[], short, short, byte)|subtract]] **(byte[] bArray,short bOff,short bLen,byte arrayFormat)          Decrements the internal big number by the specified operand value | | ** void** | **[[javacard:java-card-api:BigNumber#toBytes(byte[], short, short, byte)|toBytes]] **(byte[] outBuf,short bOff,short numBytes,byte arrayFormat)          Writes the internal big number out in the desired format. |   ^ Methods inherited from class java.lang.Object ^ | [[javacard:java-card-api:Object#equals(java.lang.Object)|equals]] |   ^ Field Detail ^ === FORMAT_BCD === public static final byte **FORMAT_BCD** Constant to indicate a BCD (binary coded decimal) data format. When this format is used a binary coded decimal digit is stored in 1 nibble (4 bits). A byte is packed with 2 BCD digits. **See Also:**[[javacard:java-card-api:constant-values#javacardx.framework.math.BigNumber.FORMAT_BCD|Constant Field Values]] ---- === FORMAT_HEX === public static final byte **FORMAT_HEX** Constant to indicate a hexadecimal (simple binary) data format. **See Also:**[[javacard:java-card-api:constant-values#javacardx.framework.math.BigNumber.FORMAT_HEX|Constant Field Values]] ^ Constructor Detail ^ === BigNumber === public **BigNumber**(short maxBytes) Creates a BigNumber instance with initial value 0. All implementations must support at least 8 byte length internal representation capacity. **Parameters:**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. **Throws:** [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - if maxBytes is 0, negative or larger than the supported maximum ^ Method Detail ^ === setMaximum === public void **setMaximum**(byte[] maxValue, short bOff, short bLen, byte arrayFormat) Sets the maximum value that the BigNumber may contain. Attempts to increase beyond the maximum results in an exception. If this method is not called, the maximum value is the maximum hex value that fits within the configured maximum number of bytes. Note: \\ *//This method may allocate internal storage to store the specified maximum value.// \\ **Parameters:**maxValue - input byte array bOff - offset within input byte array containing first byte (the high order byte) bLen - byte length of input data arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Throws:** [[javacard:java-card-api:NullPointerException|NullPointerException]] - if maxValue is null [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the input array would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the specified maximum value is smaller than the encapsulated big number \\ *if the specified maximum value is larger than will fit within the supported maximum number of bytes \\ *if the input byte array format is not conformant with the specified arrayFormat parameter \\ *if bLen is 0 \\ *if arrayFormat is not one of the FORMAT_ constants. \\ ---- === getMaxBytesSupported === public static short **getMaxBytesSupported**() This method returns the byte length of the hex array that can store the biggest BigNumber supported. This number is the maximum number in hex byte representation. All implementations must support at least 8 bytes. **Returns:**the byte length of the biggest number supported ---- === init === public void **init**(byte[] bArray, short bOff, short bLen, byte arrayFormat) throws [[javacard:java-card-api:NullPointerException|NullPointerException]] , [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] , [[javacard:java-card-api:ArithmeticException|ArithmeticException]] Initializes the big number using the input data **Parameters:**bArray - input byte array bOff - offset within byte array containing first byte (the high order byte) bLen - byte length of input data arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the input array would cause access outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if bArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the input byte array format is not conformant with the specified arrayFormat parameter \\ *if the specified input data represents a number which is larger than the maximum value configured or larger than will fit within the supported maximum number of bytes \\ *if bLen is 0 \\ *if arrayFormat is not one of the FORMAT_ constants. \\ ---- === add === public void **add**(byte[] bArray, short bOff, short bLen, byte arrayFormat) throws [[javacard:java-card-api:NullPointerException|NullPointerException]] , [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] , [[javacard:java-card-api:ArithmeticException|ArithmeticException]] Increments the internal big number by the specified operand value **Parameters:**bArray - input byte array bOff - offset within input byte array containing first byte (the high order byte) bLen - byte length of input data arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the input array would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if bArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the input byte array format is not conformant with the specified arrayFormat parameter \\ *if the result of the addition results in a big number which cannot be represented within the maximum supported bytes or is greater than the configured max value. The internal big number is left unchanged. \\ *if bLen is 0 \\ *if arrayFormat is not one of the FORMAT_ constants \\ ---- === subtract === public void **subtract**(byte[] bArray, short bOff, short bLen, byte arrayFormat) throws [[javacard:java-card-api:ArithmeticException|ArithmeticException]] Decrements the internal big number by the specified operand value **Parameters:**bArray - input byte array bOff - offset within input byte array containing first byte (the high order byte) bLen - byte length of input data arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the input array would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if bArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the input byte array format is not conformant with the specified arrayFormat parameter \\ *if the result of the subtraction results in a negative number. The internal big number is left unchanged. \\ *if bLen is 0 \\ *if arrayFormat is not one of the FORMAT_ constants. \\ ---- === multiply === public void **multiply**(byte[] bArray, short bOff, short bLen, byte arrayFormat) throws [[javacard:java-card-api:ArithmeticException|ArithmeticException]] Multiplies the internal big number by the specified operand value **Parameters:**bArray - input byte array bOff - offset within input byte array containing first byte (the high order byte) bLen - byte length of input data arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the input array would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if bArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the input byte array format is not conformant with the specified arrayFormat parameter \\ *if the result of the multiplication results in a big number which cannot be represented within the maximum supported bytes or is greater than the configured max value. The internal big number is left unchanged. \\ *if bLen is 0 \\ *if arrayFormat is not one of the FORMAT_ constants. \\ ---- === compareTo === public byte **compareTo**([[javacard:java-card-api:BigNumber|BigNumber]]  operand) Compares the internal big number against the specified operand **Parameters:**operand - contains the BigNumber operand **Returns:**the result of the comparison as follows: \\ *0 if equal \\ *-1 if the internal big number is less than the specified operand \\ *1 if the internal big number is greater than the specified operand \\ **Throws:** [[javacard:java-card-api:NullPointerException|NullPointerException]] - if operand is null ---- === compareTo === public byte **compareTo**(byte[] bArray, short bOff, short bLen, byte arrayFormat) Compares the internal big number against the specified operand. The operand is specified in an input byte array. **Parameters:**bArray - input byte array bOff - offset within input byte array containing first byte (the high order byte) bLen - byte length of input data arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Returns:**the result of the comparison as follows: \\ *0 if equal \\ *-1 if the internal big number is less than the specified operand \\ *1 if the internal big number is greater than the specified operand \\ **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the input array would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if bArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the input byte array format is not conformant with the specified arrayFormat parameter \\ *if bLen is 0 \\ *if arrayFormat is not one of the FORMAT_ constants. \\ ---- === toBytes === public void **toBytes**(byte[] outBuf, short bOff, short numBytes, byte arrayFormat) throws [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] , [[javacard:java-card-api:NullPointerException|NullPointerException]] Writes the internal big number out in the desired format. Note that the value output into the specified byte array is right justified for the number of requested bytes. BCD 0 nibbles are prepended to the output BCD data written out. **Parameters:**outBuf - output byte array bOff - offset within byte array containing first byte (the high order byte) numBytes - number of output bytes required arrayFormat - indicates the format of the input data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if accessing the output array would cause access of data outside array bounds or if numBytes is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if outBuf is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if numBytes is not sufficient to represent the big number in the desired format \\ *if numBytes is 0 \\ *if arrayFormat is not one of the FORMAT_ constants. \\ ---- === getByteLength === public short **getByteLength**(byte arrayFormat) Returns the number of bytes required to represent the big number using the desired format **Parameters:**arrayFormat - indicates the format of the output data. Valid codes listed in FORMAT_* constants. See [[javacard:java-card-api:BigNumber#FORMAT_BCD|FORMAT_BCD]] . **Returns:**the byte length of big number **Throws:** [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - if arrayFormat is not one of the FORMAT_ constants. ---- === reset === public void **reset**() Resets the big number to 0