BCDUtil (Java Card API, Connected Edition)
Date: 2009-12-11

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javacardx.framework.math
Class BCDUtil

    java.lang.Object
      javacardx.framework.math.BCDUtil

    @TransactionType(value=SUPPORTS)
    public final class BCDUtil

extends 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
`BCDUtil()` Intended to be package visible.

Method Summary
`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.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### BCDUtil

    public BCDUtil()

  Intended to be package visible. Retain for compatibility

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` 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:
    `ArrayIndexOutOfBoundsException` - if converting would cause access of data outside array bounds or if `bLen` is negative
    `NullPointerException` - if either `bcdArray` or `hexArray` is `null`
    `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:
    `ArrayIndexOutOfBoundsException` - if converting would cause access of data outside array bounds or if `bLen` is negative
    `NullPointerException` - if either `bcdArray` or `hexArray` is `null`
    `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:
    `ArrayIndexOutOfBoundsException` - if accessing the input array would cause access of data outside array bounds or if `bLen` is negative
    `NullPointerException` - if `bcdArray` is `null`
    `ArithmeticException` - if `bLen` is 0

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.