Package com.solab.iso8583.util
Class Bcd
- java.lang.Object
-
- com.solab.iso8583.util.Bcd
-
public final class Bcd extends java.lang.ObjectRoutines for Binary Coded Digits.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.math.BigIntegerdecodeRightPaddedToBigInteger(byte[] buf, int pos, int length)Decodes a right-padded BCD-encoded number as a BigInteger.static longdecodeRightPaddedToLong(byte[] buf, int pos, int length)static java.math.BigIntegerdecodeToBigInteger(byte[] buf, int pos, int length)Decodes a BCD-encoded number as a BigInteger.static longdecodeToLong(byte[] buf, int pos, int length)Decodes a BCD-encoded number as a long.static voidencode(java.lang.String value, byte[] buf)Encode the value as BCD and put it in the buffer.static voidencodeRightPadded(java.lang.String value, byte[] buf)Encode the value as BCD and put it in the buffer.static intparseBcdLength(byte b)Convert two bytes of BCD length to an int, e.g.static intparseBcdLength2bytes(byte[] b, int offset)Convert two bytes of BCD length to an int, e.g.
-
-
-
Method Detail
-
decodeToLong
public static long decodeToLong(byte[] buf, int pos, int length) throws java.lang.IndexOutOfBoundsExceptionDecodes a BCD-encoded number as a long.- Parameters:
buf- The byte buffer containing the BCD data.pos- The starting position in the buffer.length- The number of DIGITS (not bytes) to read.- Throws:
java.lang.IndexOutOfBoundsException
-
decodeRightPaddedToLong
public static long decodeRightPaddedToLong(byte[] buf, int pos, int length) throws java.lang.IndexOutOfBoundsException- Throws:
java.lang.IndexOutOfBoundsException
-
encode
public static void encode(java.lang.String value, byte[] buf)Encode the value as BCD and put it in the buffer. The buffer must be big enough to store the digits in the original value (half the length of the string).
-
encodeRightPadded
public static void encodeRightPadded(java.lang.String value, byte[] buf)Encode the value as BCD and put it in the buffer. The buffer must be big enough to store the digits in the original value (half the length of the string). If the value contains an odd number of digits, the last one is stored in its own byte at the end, padded with an F nibble.
-
decodeToBigInteger
public static java.math.BigInteger decodeToBigInteger(byte[] buf, int pos, int length) throws java.lang.IndexOutOfBoundsExceptionDecodes a BCD-encoded number as a BigInteger.- Parameters:
buf- The byte buffer containing the BCD data.pos- The starting position in the buffer.length- The number of DIGITS (not bytes) to read.- Throws:
java.lang.IndexOutOfBoundsException
-
decodeRightPaddedToBigInteger
public static java.math.BigInteger decodeRightPaddedToBigInteger(byte[] buf, int pos, int length) throws java.lang.IndexOutOfBoundsExceptionDecodes a right-padded BCD-encoded number as a BigInteger.- Parameters:
buf- The byte buffer containing the BCD data.pos- The starting position in the buffer.length- The number of DIGITS (not bytes) to read.- Throws:
java.lang.IndexOutOfBoundsException
-
parseBcdLength
public static int parseBcdLength(byte b)
Convert two bytes of BCD length to an int, e.g. 0x4521 into 4521, starting at the specified offset.
-
parseBcdLength2bytes
public static int parseBcdLength2bytes(byte[] b, int offset)Convert two bytes of BCD length to an int, e.g. 0x4521 into 4521, starting at the specified offset.
-
-