Package javacardx.framework.math
Class BCDUtil
- java.lang.Object
-
- javacardx.framework.math.BCDUtil
-
public final class BCDUtil extends Object
TheBCDUtilclass contains common BCD(binary coded decimal) related utility functions. This class supports Packed BCD format. All methods in this class are static.The
BCDUtilclass 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
Constructors Constructor Description BCDUtil()Intended to be package visible.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static shortconvertToBCD(byte[] hexArray, short bOff, short bLen, byte[] bcdArray, short outOff)Converts the input hexadecimal data into BCD format.static shortconvertToHex(byte[] bcdArray, short bOff, short bLen, byte[] hexArray, short outOff)Converts the input BCD data into hexadecimal format.static shortgetMaxBytesSupported()This method returns the largest value that can be used with the BCD utility functions.static booleanisBCDFormat(byte[] bcdArray, short bOff, short bLen)Checks if the input data is in BCD format.
-
-
-
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 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
bOfforbLenoroutOffparameter is negative anArrayIndexOutOfBoundsExceptionexception is thrown. - If
bOff+bLenis greater thanbcdArray.length, the length of thebcdArrayarray aArrayIndexOutOfBoundsExceptionexception 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 thehexArrayarray anArrayIndexOutOfBoundsExceptionexception is thrown and no conversion is performed. - If
bcdArrayorhexArrayparameter isnullaNullPointerExceptionexception is thrown. - If the
bcdArrayandhexArrayarguments refer to the same array object, or if any of these arguments refer to an array view sharing components with the other argument, then the conversion is performed as if the components at positionsbOffthroughbOff+bLen-1were first copied to a temporary array withbLencomponents and then the contents of the temporary array were converted into positionsoutOffonwards for the converted bytes of the output array.
- Parameters:
bcdArray- input byte arraybOff- offset within byte array containing first byte (the high order byte)bLen- byte length of input BCD datahexArray- output byte arrayoutOff- offset within hexArray where output data begins- Returns:
- the byte length of the output hexadecimal data
- Throws:
ArrayIndexOutOfBoundsException- if converting would cause access of data outside array bounds or ifbLenis negativeNullPointerException- if eitherbcdArrayorhexArrayisnullArithmeticException- 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
bLenis 0
- If
-
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
bOfforbLenoroutOffparameter is negative anArrayIndexOutOfBoundsExceptionexception is thrown. - If
bOff+bLenis greater thanhexArray.length, the length of thehexArrayarray aArrayIndexOutOfBoundsExceptionexception 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 thebcdArrayarray anArrayIndexOutOfBoundsExceptionexception is thrown and no conversion is performed. - If
bcdArrayorhexArrayparameter isnullaNullPointerExceptionexception is thrown. - If the
bcdArrayandhexArrayarguments refer to the same array object, or if any of these arguments refer to an array view sharing components with the other argument, then the conversion is performed as if the components at positionsbOffthroughbOff+bLen-1were first copied to a temporary array withbLencomponents and then the contents of the temporary array were converted into positionsoutOffonwards for the converted bytes of the output array.
- Parameters:
hexArray- input byte arraybOff- offset within byte array containing first byte (the high order byte)bLen- byte length of input hex databcdArray- output byte arrayoutOff- offset within bcdArray where output data begins- Returns:
- the byte length of the output bcd formatted data
- Throws:
ArrayIndexOutOfBoundsException- if converting would cause access of data outside array bounds or ifbLenis negativeNullPointerException- if eitherbcdArrayorhexArrayisnullArithmeticException- for the following conditions:- if the length of the input hex value is larger than the supported maximum number of bytes
- if
bLenis 0
- If
-
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 arraybOff- 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:
ArrayIndexOutOfBoundsException- if accessing the input array would cause access of data outside array bounds or ifbLenis negativeNullPointerException- ifbcdArrayisnullArithmeticException- ifbLenis 0
-
-