- java.lang.Object
-
- com.ibm.dataaccess.DecimalData
-
public final class DecimalData extends Object
Routines to convert between decimal data types stored in byte arrays and Java binary types.All the converter routines require the precision of the decimal value to convert, which represents the number of decimal digits in the decimal value, not including the sign.
Unicode Decimal values can be represented as either a char array or as a byte array where every Unicode character is represented by a pair of adjacent bytes.
For embedded sign nibbles (4 bit integers representing values between
0x0and0xFinclusive) in External Decimal or Packed Decimal data,0xBand0xDrepresent a negative sign. All other sign nibble values represent a positive sign. For operations that produce an External Decimal or Packed Decimal result, the Data Access Accelerator library inserts the preferred positive sign code of0xCif the result is positive, and a preferred negative sign code of0xDif the result is negative. All values between0x0and0xFinclusive are interpreted as valid sign codes.This library has full support for signed integers but only limited support for scale points (decimals). Scale points and other unrecognized characters found in input External, Unicode, or Packed Decimal byte arrays are not supported, and may cause IllegalArgumentExceptions or undefined results. BigDecimal inputs will have scale ignored (i.e. -1.23 will be interpreted as -123). When converting to BigDecimal (as output), a scale value may be explicitly specified as a separate parameter.
-
-
Field Summary
Fields Modifier and Type Field Description static intEBCDIC_SIGN_EMBEDDED_LEADINGExternal Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the first byte.static intEBCDIC_SIGN_EMBEDDED_TRAILINGExternal Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the last byte.static intEBCDIC_SIGN_SEPARATE_LEADINGExternal Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes before the first byte of the number.static intEBCDIC_SIGN_SEPARATE_TRAILINGExternal Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes after the last byte of the number.static intUNICODE_SIGN_SEPARATE_LEADINGUnicode Decimal data format where each digit is a Unicode character, the sign is stored in the first character.static intUNICODE_SIGN_SEPARATE_TRAILINGUnicode Decimal data format where each digit is a Unicode character, the sign is stored in the last character.static intUNICODE_UNSIGNEDUnicode Decimal data format where each digit is a Unicode character, there is no sign.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidconvertBigDecimalToExternalDecimal(BigDecimal bigDecimalValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a BigDecimal value to an External Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array.static voidconvertBigDecimalToPackedDecimal(BigDecimal bigDecimalValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a BigDecimal into a Packed Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array.static voidconvertBigDecimalToUnicodeDecimal(BigDecimal bigDecimalValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a BigDecimal value to a Unicode Decimal in a char array Overflow can happen if the BigDecimal does not fit into the result char array.static voidconvertBigIntegerToExternalDecimal(BigInteger bigIntegerValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a BigInteger value into an External Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array.static voidconvertBigIntegerToPackedDecimal(BigInteger bigIntegerValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a BigInteger value into a Packed Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array.static voidconvertBigIntegerToUnicodeDecimal(BigInteger bigIntegerValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a BigInteger value to a Unicode Decimal in a char array Overflow can happen if the BigInteger does not fit into the char array.static BigDecimalconvertExternalDecimalToBigDecimal(byte[] externalDecimal, int offset, int precision, int scale, boolean checkOverflow, int decimalType)Converts an External Decimal in a byte array to a BigDecimal.static BigIntegerconvertExternalDecimalToBigInteger(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Convert an External Decimal in a byte array to a BigInteger.static intconvertExternalDecimalToInteger(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts an External Decimal value in a byte array into a binary integer.static longconvertExternalDecimalToLong(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts an External Decimal value in a byte array into a long.static voidconvertExternalDecimalToPackedDecimal(byte[] externalDecimal, int externalOffset, byte[] packedDecimal, int packedOffset, int precision, int decimalType)Converts an External Decimal in a byte array to a Packed Decimal in another byte array.static voidconvertIntegerToExternalDecimal(int integerValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts an integer to an External Decimal in a byte array.static voidconvertIntegerToPackedDecimal(int integerValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a binary integer value into a signed Packed Decimal format.static voidconvertIntegerToUnicodeDecimal(int integerValue, char[] unicodeDecimal, int offset, int precision, boolean checkoverflow, int unicodeType)Converts an integer to a Unicode Decimal in a char array Overflow can happen if the resulting External Decimal value does not fit into the char array, given the offset and precision.static voidconvertLongToExternalDecimal(long longValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a long into an External Decimal in a byte array.static voidconvertLongToPackedDecimal(long longValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a binary long value into signed Packed Decimal format.static voidconvertLongToUnicodeDecimal(long longValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a long to a Unicode Decimal in a char array Overflow can happen if the resulting Unicode Decimal value does not fit into the char array, given its precision and offset .static BigDecimalconvertPackedDecimalToBigDecimal(byte[] packedDecimal, int offset, int precision, int scale, boolean checkOverflow)Convert a Packed Decimal in a byte array to a BigDecimal.static BigIntegerconvertPackedDecimalToBigInteger(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Convert a Packed Decimal in a byte array to a BigInteger.static voidconvertPackedDecimalToExternalDecimal(byte[] packedDecimal, int packedOffset, byte[] externalDecimal, int externalOffset, int precision, int decimalType)Converts a Packed Decimal in a byte array into an External Decimal in another byte array.static intconvertPackedDecimalToInteger(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a Packed Decimal value in a byte array into a binary integer.static longconvertPackedDecimalToLong(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a Packed Decimal value in a byte array into a binary long.static voidconvertPackedDecimalToUnicodeDecimal(byte[] packedDecimal, int packedOffset, char[] unicodeDecimal, int unicodeOffset, int precision, int decimalType)Convert a Packed Decimal in a byte array to a Unicode Decimal in a char array.static BigDecimalconvertUnicodeDecimalToBigDecimal(char[] unicodeDecimal, int offset, int precision, int scale, boolean checkOverflow, int decimalType)Converts a Unicode Decimal in a char array to a BigDecimal.static BigIntegerconvertUnicodeDecimalToBigInteger(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Convert a Unicode Decimal in a char array to a BigInteger.static intconvertUnicodeDecimalToInteger(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int unicodeType)Converts a Unicode Decimal value in a char array into a binary integer.static longconvertUnicodeDecimalToLong(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int unicodeType)Converts a Unicode Decimal value in a char array into a binary long.static voidconvertUnicodeDecimalToPackedDecimal(char[] unicodeDecimal, int unicodeOffset, byte[] packedDecimal, int packedOffset, int precision, int decimalType)Converts an Unicode Decimal in a char array to a Packed Decimal in a byte array.
-
-
-
Field Detail
-
EBCDIC_SIGN_EMBEDDED_TRAILING
public static final int EBCDIC_SIGN_EMBEDDED_TRAILING
External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the last byte.- See Also:
- Constant Field Values
-
EBCDIC_SIGN_EMBEDDED_LEADING
public static final int EBCDIC_SIGN_EMBEDDED_LEADING
External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in the top nibble of the first byte.- See Also:
- Constant Field Values
-
EBCDIC_SIGN_SEPARATE_TRAILING
public static final int EBCDIC_SIGN_SEPARATE_TRAILING
External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes after the last byte of the number.- See Also:
- Constant Field Values
-
EBCDIC_SIGN_SEPARATE_LEADING
public static final int EBCDIC_SIGN_SEPARATE_LEADING
External Decimal data format where each byte is an EBCDIC character representing a decimal digit, the sign is encoded in a separate byte that comes before the first byte of the number.- See Also:
- Constant Field Values
-
UNICODE_UNSIGNED
public static final int UNICODE_UNSIGNED
Unicode Decimal data format where each digit is a Unicode character, there is no sign.- See Also:
- Constant Field Values
-
UNICODE_SIGN_SEPARATE_LEADING
public static final int UNICODE_SIGN_SEPARATE_LEADING
Unicode Decimal data format where each digit is a Unicode character, the sign is stored in the first character.- See Also:
- Constant Field Values
-
UNICODE_SIGN_SEPARATE_TRAILING
public static final int UNICODE_SIGN_SEPARATE_TRAILING
Unicode Decimal data format where each digit is a Unicode character, the sign is stored in the last character.- See Also:
- Constant Field Values
-
-
Method Detail
-
convertIntegerToPackedDecimal
public static void convertIntegerToPackedDecimal(int integerValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a binary integer value into a signed Packed Decimal format. The Packed Decimal will be padded with zeros on the left if necessary. Overflow can happen if the resulting Packed Decimal does not fit into the result byte array, given the offset and precision. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
integerValue- the binary integer value to convertpackedDecimal- byte array that will store the resulting Packed Decimal valueoffset- offset of the first byte of the Packed Decimal inpackedDecimalprecision- number of Packed Decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalis nullArithmeticException- if thecheckOverflowparameter is true and overflow occurs
-
convertIntegerToExternalDecimal
public static void convertIntegerToExternalDecimal(int integerValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts an integer to an External Decimal in a byte array. The External Decimal will be padded with zeros on the left if necessary. Overflow can happen if the resulting External Decimal value does not fit into the byte array, given the precision and offset. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
integerValue- the value to convertexternalDecimal- the byte array which will hold the External Decimal on a successful returnoffset- the offset in the byte array at which the External Decimal should be locatedprecision- the number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the designated array cannot hold the External Decimal.decimalType- constant value indicating the type of External Decimal- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- if thecheckOverflowparameter is true and overflow occursIllegalArgumentException- ifdecimalTypeorprecisionis invalid
-
convertIntegerToUnicodeDecimal
public static void convertIntegerToUnicodeDecimal(int integerValue, char[] unicodeDecimal, int offset, int precision, boolean checkoverflow, int unicodeType)Converts an integer to a Unicode Decimal in a char array Overflow can happen if the resulting External Decimal value does not fit into the char array, given the offset and precision. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
integerValue- the long value to convertunicodeDecimal- the char array which will hold the Unicode Decimal on a successful returnoffset- the offset in the char array where the Unicode Decimal would be locatedprecision- the number of decimal digits. Maximum valid precision is 253checkoverflow- if true, when the designated anArithmeticExceptionunicodeType- constant value indicating the type of Unicode Decimal- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- if thecheckOverflowparameter is true and overflow occursIllegalArgumentException- if thedecimalTypeorprecisionis invalid
-
convertLongToPackedDecimal
public static void convertLongToPackedDecimal(long longValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a binary long value into signed Packed Decimal format. The Packed Decimal will be padded with zeros on the left if necessary. Overflow can happen if the resulting Packed Decimal does not fit into the result byte array, given the offset and precision . In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
longValue- the binary long value to convertpackedDecimal- byte array that will store the resulting Packed Decimal valueoffset- offset of the first byte of the Packed Decimal inpackedDecimalprecision- number of Packed Decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow), otherwise a truncated value is returned- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalis nullArithmeticException- thecheckOverflowparameter is true and overflow occurs
-
convertLongToExternalDecimal
public static void convertLongToExternalDecimal(long longValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a long into an External Decimal in a byte array. The External Decimal will be padded with zeros on the left if necessary. Overflow can happen if the External Decimal value does not fit into the byte array, given its precision and offset. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
longValue- the value to convertexternalDecimal- the byte array which will hold the External Decimal on a successful returnoffset- the offset intoexternalDecimalwhere External Decimal should be locatedprecision- the number of decimal digits to convert. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionorIllegalArgumentExceptionmay be throwndecimalType- constant value indicating the type of External Decimal- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- if thecheckOverflowparameter is true and overflow occursIllegalArgumentException- if thedecimalTypeorprecisionis invalid
-
convertLongToUnicodeDecimal
public static void convertLongToUnicodeDecimal(long longValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts a long to a Unicode Decimal in a char array Overflow can happen if the resulting Unicode Decimal value does not fit into the char array, given its precision and offset . In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
longValue- the long value to convertunicodeDecimal- the char array which will hold the Unicode Decimal on a successful returnoffset- the offset in the char array where the Unicode Decimal would be locatedprecision- the number of Unicode Decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionorIllegalArgumentExceptionmay be throwndecimalType- constant value indicating the type of External Decimal- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- if thecheckOverflowparameter is true and overflow occursIllegalArgumentException- ifdecimalTypeorprecisionis invalid
-
convertPackedDecimalToInteger
public static int convertPackedDecimalToInteger(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a Packed Decimal value in a byte array into a binary integer. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into a binary integer. WhencheckOverflowis true overflow results in anArithmeticException, when false a truncated or invalid result is returned.- Parameters:
packedDecimal- byte array which contains the Packed Decimal valueoffset- offset of the first byte of the Packed Decimal inpackedDecimalprecision- number of Packed Decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionmay be thrown- Returns:
- int the resulting binary integer value
- Throws:
NullPointerException- ifpackedDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result does not fit into an int (overflow)
-
convertPackedDecimalToLong
public static long convertPackedDecimalToLong(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)Converts a Packed Decimal value in a byte array into a binary long. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into a binary long. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
packedDecimal- byte array which contains the Packed Decimal valueoffset- offset of the first byte of the Packed Decimal inpackedDecimalprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionmay be thrown- Returns:
- long the resulting binary long value
- Throws:
NullPointerException- ifpackedDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result does not fit into a long (overflow)
-
convertPackedDecimalToExternalDecimal
public static void convertPackedDecimalToExternalDecimal(byte[] packedDecimal, int packedOffset, byte[] externalDecimal, int externalOffset, int precision, int decimalType)Converts a Packed Decimal in a byte array into an External Decimal in another byte array. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative.- Parameters:
packedDecimal- byte array that holds the Packed Decimal to be convertedpackedOffset- offset inpackedDecimalwhere the Packed Decimal is locatedexternalDecimal- byte array that will hold the External Decimal on a successful returnexternalOffset- offset inexternalOffsetwhere the External Decimal is expected to be locatedprecision- number of decimal digitsdecimalType- constant indicating the type of the decimal- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalorexternalDecimalare nullIllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertPackedDecimalToUnicodeDecimal
public static void convertPackedDecimalToUnicodeDecimal(byte[] packedDecimal, int packedOffset, char[] unicodeDecimal, int unicodeOffset, int precision, int decimalType)Convert a Packed Decimal in a byte array to a Unicode Decimal in a char array. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative.- Parameters:
packedDecimal- byte array that holds a Packed Decimal to be convertedpackedOffset- offset inpackedDecimalwhere the Packed Decimal is locatedunicodeDecimal- char array that will hold the Unicode Decimal on a successful returnunicodeOffset- offset in the byte array where the Unicode Decimal is expected to be locatedprecision- number of decimal digitsdecimalType- constant value indicating the type of the External Decimal- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalorunicodeDecimalare nullIllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertPackedDecimalToBigInteger
public static BigInteger convertPackedDecimalToBigInteger(byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
Convert a Packed Decimal in a byte array to a BigInteger. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into the BigInteger. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
packedDecimal- byte array that holds the Packed Decimal to be convertedoffset- offset inpackedDecimalwhere the Packed Decimal is locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)- Returns:
- BigInteger the resulting BigInteger
- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalis null
-
convertPackedDecimalToBigDecimal
public static BigDecimal convertPackedDecimalToBigDecimal(byte[] packedDecimal, int offset, int precision, int scale, boolean checkOverflow)
Convert a Packed Decimal in a byte array to a BigDecimal. If the digital part of the input Packed Decimal is not valid then the digital part of the output will not be valid. The sign of the input Packed Decimal is assumed to to be positive unless the sign nibble contains one of the negative sign codes, in which case the sign of the input Packed Decimal is interpreted as negative. Overflow can happen if the Packed Decimal value does not fit into the BigDecimal. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
packedDecimal- byte array that holds the Packed Decimal to be convertedoffset- offset inpackedDecimalwhere the Packed Decimal is locatedprecision- number of decimal digits. Maximum valid precision is 253scale- scale of the BigDecimal to be returnedcheckOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)- Returns:
- BigDecimal the resulting BigDecimal
- Throws:
NullPointerException- ifpackedDecimalis nullArrayIndexOutOfBoundsException- /requires rounding if an invalid array access occurs
-
convertExternalDecimalToInteger
public static int convertExternalDecimalToInteger(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts an External Decimal value in a byte array into a binary integer. If the digital part of the input External Decimal is not valid then the digital part of the output will not be valid. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending ondecimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into a binary integer. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false the resulting number will be wrapped around starting at the minimum/maximum possible integer value.- Parameters:
externalDecimal- byte array which contains the External Decimal valueoffset- the offset where the External Decimal value is locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionorIllegalArgumentExceptionmay be thrown. If false and there is an overflow, the result is undefined.decimalType- constant value indicating the type of External Decimal- Returns:
- int the resulting binary integer
- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result does not fit into a int (overflow)IllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertExternalDecimalToLong
public static long convertExternalDecimalToLong(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)Converts an External Decimal value in a byte array into a long. If the digital part of the input External Decimal is not valid then the digital part of the output will not be valid. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending ondecimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into a binary long. WhencheckOverflowis true overflow results in anArithmeticException, when false the resulting number will be wrapped around starting at the minimum/maximum possible long value.- Parameters:
externalDecimal- byte array which contains the External Decimal valueoffset- offset of the first byte of the Packed Decimal in theexternalDecimalprecision- number of External Decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown when the converted value cannot fit into designated External Decimal array. If false and there is an overflow, the result is undefined.decimalType- constant value indicating the type of External Decimal- Returns:
- long the resulting binary long value
- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result does not fit into a long (overflow)IllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertExternalDecimalToPackedDecimal
public static void convertExternalDecimalToPackedDecimal(byte[] externalDecimal, int externalOffset, byte[] packedDecimal, int packedOffset, int precision, int decimalType)Converts an External Decimal in a byte array to a Packed Decimal in another byte array. If the digital part of the input External Decimal is not valid then the digital part of the output will not be valid. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending ondecimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative.- Parameters:
externalDecimal- byte array holding the External Decimal to be convertedexternalOffset- offset inexternalDecimalwhere the External Decimal is locatedpackedDecimal- byte array which will hold the Packed Decimal on a successful returnpackedOffset- offset inpackedDecimalwhere the Packed Decimal is expected to be locatedprecision- the number of decimal digitsdecimalType- constant value indicating the type of External Decimal- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalorexternalDecimalis nullIllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertExternalDecimalToBigInteger
public static BigInteger convertExternalDecimalToBigInteger(byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
Convert an External Decimal in a byte array to a BigInteger. The sign of the input External Decimal is assumed to to be positive unless the sign nibble or byte (depending ondecimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into the BigInteger. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
externalDecimal- byte array that holds the Packed Decimal to be convertedoffset- offset inexternalDecimalwhere the Packed Decimal is locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value indicating the type of External Decimal- Returns:
- BigInteger the resulting BigInteger
- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifexternalDecimalis nullArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifdecimalTypeorprecisionis invalid, or the digital part of the input is invalid.
-
convertExternalDecimalToBigDecimal
public static BigDecimal convertExternalDecimalToBigDecimal(byte[] externalDecimal, int offset, int precision, int scale, boolean checkOverflow, int decimalType)
Converts an External Decimal in a byte array to a BigDecimal. The sign of the input External Decimal is assumed to be positive unless the sign nibble or byte (depending ondecimalType) contains one of the negative sign codes, in which case the sign of the input External Decimal is interpreted as negative. Overflow can happen if the External Decimal value does not fit into the BigDecimal. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
externalDecimal- byte array holding the External Decimal to be convertedoffset- offset inexternalDecimalwhere the External Decimal is locatedprecision- number of decimal digits. Maximum valid precision is 253scale- scale of the BigDecimalcheckOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value that indicates the type of External Decimal- Returns:
- BigDecimal the resulting BigDecimal
- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifcheckOverflowis true and the Packed Decimal is in an invalid format, or the digital part of the input is invalid.
-
convertUnicodeDecimalToInteger
public static int convertUnicodeDecimalToInteger(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int unicodeType)Converts a Unicode Decimal value in a char array into a binary integer. The sign of the input Unicode Decimal is assumed to be positive unless the sign char contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into a binary int. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
unicodeDecimal- char array which contains the Unicode Decimal valueoffset- the offset where the Unicode Decimal value is locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionorIllegalArgumentExceptionmay be thrownunicodeType- constant value indicating the type of External Decimal- Returns:
- int the resulting binary integer
- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result does not fit into a long (overflow)IllegalArgumentException- ifprecisionordecimalTypeis invalid, or the digital part of the input is invalid.
-
convertUnicodeDecimalToLong
public static long convertUnicodeDecimalToLong(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int unicodeType)Converts a Unicode Decimal value in a char array into a binary long. The sign of the input Unicode Decimal is assumed to be positive unless the sign char contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into a binary long. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
unicodeDecimal- char array which contains the External Decimal valueoffset- offset of the first byte of the Unicode Decimal inunicodeDecimalprecision- number of Unicode Decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown whenunicodeType- constant value indicating the type of External Decimal- Returns:
- long the resulting binary long value
- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result does not fit into a long (overflow)IllegalArgumentException- ifunicodeTypeorprecisionis invalid, or the digital part of the input is invalid.
-
convertUnicodeDecimalToPackedDecimal
public static void convertUnicodeDecimalToPackedDecimal(char[] unicodeDecimal, int unicodeOffset, byte[] packedDecimal, int packedOffset, int precision, int decimalType)Converts an Unicode Decimal in a char array to a Packed Decimal in a byte array. If the digital part of the input Unicode Decimal is not valid then the digital part of the output will not be valid. The sign of the input Unicode Decimal is assumed to be positive unless the sign byte contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative.- Parameters:
unicodeDecimal- char array that holds the Unicode Decimal to be convertedunicodeOffset- offset inunicodeDecimalat which the Unicode Decimal is locatedpackedDecimal- byte array that will hold the Packed Decimal on a successful returnpackedOffset- offset inpackedDecimalwhere the Packed Decimal is expected to be locatedprecision- number of decimal digitsdecimalType- constant value indicating the type of External Decimal- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifpackedDecimalorunicodeDecimalare nullIllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertUnicodeDecimalToBigInteger
public static BigInteger convertUnicodeDecimalToBigInteger(char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
Convert a Unicode Decimal in a char array to a BigInteger. The sign of the input Unicode Decimal is assumed to be positive unless the sign byte contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into a binary long. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
unicodeDecimal- char array that holds the Packed Decimal to be convertedoffset- offset intounicodeDecimalwhere the Packed Decimal is locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value indicating the type of External Decimal- Returns:
- BigInteger the resulting BigInteger
- Throws:
ArrayIndexOutOfBoundsException- if an invalid array access occursNullPointerException- ifunicodeDecimalis nullArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifdecimalTypeorprecisionis invalid, or the digital part of the input is invalid.
-
convertUnicodeDecimalToBigDecimal
public static BigDecimal convertUnicodeDecimalToBigDecimal(char[] unicodeDecimal, int offset, int precision, int scale, boolean checkOverflow, int decimalType)
Converts a Unicode Decimal in a char array to a BigDecimal. The sign of the input Unicode Decimal is assumed to to be positive unless the sign byte contains the negative sign code, in which case the sign of the input Unicode Decimal is interpreted as negative. Overflow can happen if the Unicode Decimal value does not fit into the BigDecimal. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
unicodeDecimal- char array that holds the Unicode Decimaloffset- offset inunicodeDecimalwhere the Unicode Decimal is locatedprecision- number of decimal digits. Maximum valid precision is 253scale- scale of the returned BigDecimalcheckOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value indicating the type of External Decimal- Returns:
- BigDecimal
- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifcheckOverflowis true and the Packed Decimal is in an invalid format, or the digital part of the input is invalid.
-
convertBigIntegerToPackedDecimal
public static void convertBigIntegerToPackedDecimal(BigInteger bigIntegerValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
Converts a BigInteger value into a Packed Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
bigIntegerValue- BigInteger value to be convertedpackedDecimal- byte array which will hold the Packed Decimal on a successful returnoffset- offset intopackedDecimalwhere the Packed Decimal is expected to be locatedprecision- number of decimal digits. Maximum valid precision is 253scheckOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)- Throws:
NullPointerException- ifpackedDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflows
-
convertBigIntegerToExternalDecimal
public static void convertBigIntegerToExternalDecimal(BigInteger bigIntegerValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
Converts a BigInteger value into an External Decimal in a byte array Overflow can happen if the BigInteger does not fit into the byte array. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
bigIntegerValue- BigInteger value to be convertedexternalDecimal- byte array which will hold the External Decimal on a successful returnoffset- offset intoexternalDecimalwhere the External Decimal is expected to be locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value that indicates the type of External Decimal- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifdecimalTypeorprecisionis invalid
-
convertBigIntegerToUnicodeDecimal
public static void convertBigIntegerToUnicodeDecimal(BigInteger bigIntegerValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
Converts a BigInteger value to a Unicode Decimal in a char array Overflow can happen if the BigInteger does not fit into the char array. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
bigIntegerValue- BigInteger value to be convertedunicodeDecimal- char array that will hold the Unicode decimal on a successful returnoffset- offset intounicodeDecimalwhere the Unicode Decimal is expected to be locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant indicating the type of External Decimal- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifdecimalTypeorprecisionis invalid
-
convertBigDecimalToPackedDecimal
public static void convertBigDecimalToPackedDecimal(BigDecimal bigDecimalValue, byte[] packedDecimal, int offset, int precision, boolean checkOverflow)
Converts a BigDecimal into a Packed Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
bigDecimalValue- the BigDecimal value to be convertedpackedDecimal- byte array which will hold the Packed Decimal on a successful returnoffset- desired offset inpackedDecimalwhere the Packed Decimal is expected to be locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)- Throws:
NullPointerException- ifpackedDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflows
-
convertBigDecimalToExternalDecimal
public static void convertBigDecimalToExternalDecimal(BigDecimal bigDecimalValue, byte[] externalDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
Converts a BigDecimal value to an External Decimal in a byte array Overflow can happen if the BigDecimal does not fit into the result byte array. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
bigDecimalValue- BigDecimal value to be convertedexternalDecimal- byte array that will hold the External Decimal on a successful returnoffset- offset inexternalDecimalwhere the External Decimal is expected to be locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value indicating the External Decimal type- Throws:
NullPointerException- ifexternalDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifprecisionordecimalTypeis invalid
-
convertBigDecimalToUnicodeDecimal
public static void convertBigDecimalToUnicodeDecimal(BigDecimal bigDecimalValue, char[] unicodeDecimal, int offset, int precision, boolean checkOverflow, int decimalType)
Converts a BigDecimal value to a Unicode Decimal in a char array Overflow can happen if the BigDecimal does not fit into the result char array. In this case, whencheckOverflowis true anArithmeticExceptionis thrown, when false a truncated or invalid result is returned.- Parameters:
bigDecimalValue- BigDecimal value to be convertedunicodeDecimal- char array which will hold the Unicode Decimal on a successful returnoffset- offset inunicodeDecimalwhere the Unicode Decimal is expected to be locatedprecision- number of decimal digits. Maximum valid precision is 253checkOverflow- if true anArithmeticExceptionwill be thrown if the decimal value does not fit in the specified precision (overflow)decimalType- constant value that indicates the type of External Decimal- Throws:
NullPointerException- ifunicodeDecimalis nullArrayIndexOutOfBoundsException- if an invalid array access occursArithmeticException- ifcheckOverflowis true and the result overflowsIllegalArgumentException- ifdecimalTypeorprecisionis invalid
-
-