Conversion classes for numeric data convert numeric data from the format used on the IBM® i (called system format in the following table) to the Java™ format.
Supported types are shown in the following table:
| Numeric Type | Description |
|---|---|
| AS400Bin2 | Converts between a signed two-byte number in the system format to a Java Short object. |
| AS400Bin4 | Converts between a signed four-byte number in the system format and a Java Integer object. |
| AS400ByteArray | Converts between two byte arrays. This is useful because the converter correctly zero-fills and pads the target buffer. |
| AS400Float4 | Converts between a signed four-byte floating point number in the system format and a Java Float object. |
| AS400Float8 | Converts between a signed eight-byte floating point number in the system format and a Java Double object. |
| AS400PackedDecimal | Converts between a packed-decimal number in the system format and a Java BigDecimal object. |
| AS400UnsignedBin2 | Converts between an unsigned two-byte number in the system format and a Java Integer object. |
| AS400UnsignedBin4 | Converts between an unsigned four-byte number in the system format and a Java Long object. |
| AS400ZonedDecimal | Converts between a zoned-decimal number in the system format and a Java BigDecimal object. |
The following examples show data conversions that use a numeric type in the system format and a Java int:
Example: Converting from the system format to a Java int
// Create a buffer to hold the system data type. Assume the buffer is
// filled with numeric data in the system format by data queues,
// program call, and so on.
byte[] data = new byte[100];
// Create a converter for this system data type.
AS400Bin4 bin4Converter = new AS400Bin4();
// Convert from system type to Java object. The number starts at the
// beginning of the buffer.
Integer intObject = (Integer) bin4Converter.toObject(data,0);
// Extract the simple Java type from the Java object.
int i = intObject.intValue();
Example: Converting from a Java int to the system format
// Create a Java object that contains the value to convert.
Integer intObject = new Integer(22);
// Create a converter for the system data type.
AS400Bin4 bin4Converter = new AS400Bin4();
// Convert from Java object to system data type.
byte[] data = bin4Converter.toBytes(intObject);
// Find out how many bytes of the buffer were filled with the
// system value.
int length = bin4Converter.getByteLength();