**javacardx.framework.math** ====Class BCDUtil ==== *[[javacard:java-card-api:object|java.lang.Object]] \\ ---- public final class **BCDUtil**extends [[javacard:java-card-api:Object|Object]] The BCDUtil class contains common BCD(binary coded decimal) related utility functions. This class supports Packed BCD format. All methods in this class are static. The BCDUtil class only supports unsigned numbers whose value can are represented in hexadecimal format using an implementation specific maximum number of bytes. **Since:** 2.2.2 ---- ^ Constructor Summary ^^ | **[[javacard:java-card-api:BCDUtil#BCDUtil()|BCDUtil]] **()            |   ^ Method Summary ^^ | **static short** | **[[javacard:java-card-api:BCDUtil#convertToBCD(byte[], short, short, byte[], short)|convertToBCD]] **(byte[] hexArray,short bOff,short bLen,byte[] bcdArray,short outOff)          Converts the input hexadecimal data into BCD format. | | **static short** | **[[javacard:java-card-api:BCDUtil#convertToHex(byte[], short, short, byte[], short)|convertToHex]] **(byte[] bcdArray,short bOff,short bLen,byte[] hexArray,short outOff)          Converts the input BCD data into hexadecimal format. | | **static short** | **[[javacard:java-card-api:BCDUtil#getMaxBytesSupported()|getMaxBytesSupported]] **()          This method returns the largest value that can be used with the BCD utility functions. | | **static boolean** | **[[javacard:java-card-api:BCDUtil#isBCDFormat(byte[], short, short)|isBCDFormat]] **(byte[] bcdArray,short bOff,short bLen)          Checks if the input data is in BCD format. |   ^ Methods inherited from class java.lang.Object ^ | [[javacard:java-card-api:Object#equals(java.lang.Object)|equals]] |   ^ Constructor Detail ^ === BCDUtil === public **BCDUtil**() ^ Method Detail ^ === getMaxBytesSupported === public static short **getMaxBytesSupported**() This method returns the largest value that can be used with the BCD utility functions. This number represents the the byte length of the largest value in hex byte representation. All implementations must support at least 8 byte length usage capacity. **Returns:**the byte length of the largest hex value supported ---- === convertToHex === public static short **convertToHex**(byte[] bcdArray, short bOff, short bLen, byte[] hexArray, short outOff) Converts the input BCD data into hexadecimal format. Note: \\ *//If //bOff// or //bLen// or //outOff// parameter is negative an //ArrayIndexOutOfBoundsException// exception is thrown.// \\ *//If //bOff+bLen// is greater than //bcdArray.length//, the length of the //bcdArray// array a //ArrayIndexOutOfBoundsException// exception is thrown and no conversion is performed.// \\ *//If the output bytes need to be written at an offset greater than //hexArray.length//, the length of the //hexArray// array an //ArrayIndexOutOfBoundsException// exception is thrown and no conversion is performed.// \\ *//If //bcdArray// or //hexArray// parameter is //null// a //NullPointerException// exception is thrown.// \\ *//If the bcdArray and hexArray arguments refer to the same array object, then the conversion is performed as if the components at positions //bOff// through //bOff+bLen-1// were first copied to a temporary array with //bLen// components and then the contents of the temporary array were converted into positions //outOff// onwards for the converted bytes of the output array.// \\ **Parameters:**bcdArray - input byte array bOff - offset within byte array containing first byte (the high order byte) bLen - byte length of input BCD data hexArray - output byte array outOff - offset within hexArray where output data begins **Returns:**the byte length of the output hexadecimal data **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if converting would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if either bcdArray or hexArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the input byte array format is not a correctly formed BCD value \\ *the size of the BCD value requires greater than supported maximum number of bytes to represent in hex format \\ *if bLen is 0 \\ ---- === convertToBCD === public static short **convertToBCD**(byte[] hexArray, short bOff, short bLen, byte[] bcdArray, short outOff) Converts the input hexadecimal data into BCD format. The output data is right justified. If the number of output BCD nibbles is odd, the first BCD nibble written is 0. Note: \\ *//If //bOff// or //bLen// or //outOff// parameter is negative an //ArrayIndexOutOfBoundsException// exception is thrown.// \\ *//If //bOff+bLen// is greater than //hexArray.length//, the length of the //hexArray// array a //ArrayIndexOutOfBoundsException// exception is thrown and no conversion is performed.// \\ *//If the output bytes need to be written at an offset greater than //bcdArray.length//, the length of the //bcdArray// array an //ArrayIndexOutOfBoundsException// exception is thrown and no conversion is performed.// \\ *//If //bcdArray// or //hexArray// parameter is //null// a //NullPointerException// exception is thrown.// \\ *//If the bcdArray and hexArray arguments refer to the same array object, then the conversion is performed as if the components at positions //bOff// through //bOff+bLen-1// were first copied to a temporary array with //bLen// components and then the contents of the temporary array were converted into positions //outOff// onwards for the converted bytes of the output array.// \\ **Parameters:**hexArray - input byte array bOff - offset within byte array containing first byte (the high order byte) bLen - byte length of input hex data bcdArray - output byte array outOff - offset within bcdArray where output data begins **Returns:**the byte length of the output bcd formatted data **Throws:** [[javacard:java-card-api:ArrayIndexOutOfBoundsException|ArrayIndexOutOfBoundsException]] - if converting would cause access of data outside array bounds or if bLen is negative [[javacard:java-card-api:NullPointerException|NullPointerException]] - if either bcdArray or hexArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - for the following conditions: \\ *if the length of the input hex value is larger than the supported maximum number of bytes \\ *if bLen is 0 \\ ---- === isBCDFormat === public static boolean **isBCDFormat**(byte[] bcdArray, short bOff, short bLen) Checks if the input data is in BCD format. Note that this method does not enforce an upper bound on the length of the input BCD value. **Parameters:**bcdArray - input byte array bOff - offset within byte array containing first byte (the high order byte) bLen - byte length of input BCD data **Returns:**true if input data is in BCD format, false otherwise **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 bcdArray is null [[javacard:java-card-api:ArithmeticException|ArithmeticException]] - if bLen is 0