Package javacardx.framework.math
Class BCDUtil
- java.lang.Object
-
- javacardx.framework.math.BCDUtil
-
public final class BCDUtil extends Object
TheBCDUtil
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
Constructors Constructor Description BCDUtil()
Intended to be package visible.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static short
convertToBCD(byte[] hexArray, short bOff, short bLen, byte[] bcdArray, short outOff)
Converts the input hexadecimal data into BCD format.static short
convertToHex(byte[] bcdArray, short bOff, short bLen, byte[] hexArray, short outOff)
Converts the input BCD data into hexadecimal format.static short
getMaxBytesSupported()
This method returns the largest value that can be used with the BCD utility functions.static boolean
isBCDFormat(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
bOff
orbLen
oroutOff
parameter is negative anArrayIndexOutOfBoundsException
exception is thrown. - If
bOff+bLen
is greater thanbcdArray.length
, the length of thebcdArray
array aArrayIndexOutOfBoundsException
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 thehexArray
array anArrayIndexOutOfBoundsException
exception is thrown and no conversion is performed. - If
bcdArray
orhexArray
parameter isnull
aNullPointerException
exception is thrown. - If the
bcdArray
andhexArray
arguments 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 positionsbOff
throughbOff+bLen-1
were first copied to a temporary array withbLen
components and then the contents of the temporary array were converted into positionsoutOff
onwards 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 ifbLen
is negativeNullPointerException
- if eitherbcdArray
orhexArray
isnull
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
- 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
bOff
orbLen
oroutOff
parameter is negative anArrayIndexOutOfBoundsException
exception is thrown. - If
bOff+bLen
is greater thanhexArray.length
, the length of thehexArray
array aArrayIndexOutOfBoundsException
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 thebcdArray
array anArrayIndexOutOfBoundsException
exception is thrown and no conversion is performed. - If
bcdArray
orhexArray
parameter isnull
aNullPointerException
exception is thrown. - If the
bcdArray
andhexArray
arguments 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 positionsbOff
throughbOff+bLen-1
were first copied to a temporary array withbLen
components and then the contents of the temporary array were converted into positionsoutOff
onwards 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 ifbLen
is negativeNullPointerException
- if eitherbcdArray
orhexArray
isnull
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
- 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 ifbLen
is negativeNullPointerException
- ifbcdArray
isnull
ArithmeticException
- ifbLen
is 0
-
-