Conversion classes for numeric data simply convert numeric data from the format used on the iSeries or AS/400e server (called server 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 server format to a Java Short object. |
| AS400Bin4 | Converts between a signed four-byte number in the server 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 server format and a Java Float object. |
| AS400Float8 | Converts between a signed eight-byte floating point number in the server format and a Java Double object. |
| AS400PackedDecimal | Converts between a packed-decimal number in the server format and a Java BigDecimal object. |
| AS400UnsignedBin2 | Converts between an unsigned two-byte number in the server format and a Java Integer object. |
| AS400UnsignedBin4 | Converts between an unsigned four-byte number in the server format and a Java Long object. |
| AS400ZonedDecimal | Converts between a zoned-decimal number in the server format and a Java BigDecimal object. |
The following example shows conversion from a numeric type in the server format to a Java int:
// Create a buffer to hold the server data
// type. Assume the buffer is filled with
// numeric data in the server format by data
// queues, program call, etc.
byte[] data = new byte[100];
// Create a converter for this
// server data type.
AS400Bin4 bin4Converter = new AS400Bin4();
// Convert from server 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();
The following example shows conversion from a Java int to a numeric data type in the server format :
// Create a Java object that contains
// the value to convert.
Integer intObject = new Integer(22);
// Create a converter for the server
// data type.
AS400Bin4 bin4Converter = new AS400Bin4();
// Convert from Java object to
// server data type.
byte[] data = bin4Converter.toBytes(intObject);
// Find out how many bytes of the
// buffer were filled with the
// server value.
int length = bin4Converter.getByteLength();