Reversing the Byte Order of Numbers

From InterBase
Jump to: navigation, search

Go Up to Working with Conversions


InterBase expects that numbers entered in database and transaction parameter buffers be in a generic format, with the least significant byte last. Signed numbers require the sign to be in the last byte. Systems that represent numbers with the most significant byte last must use the isc_portable_integer() API function to reverse the byte order of numbers entered in DPBs and TPBs. When numeric information is returned by information calls on these systems, isc_portable_integer() must be used once again to reverse the byte ordering. The syntax for isc_portable_integer() is:

ISC_LONG isc_portable_integer( char *buffer, short length);

buffer is a char pointer to the integer to convert, and length is the size, in bytes, of the integer. Valid lengths are 1 (short), 2 (int), 4(long), and 8(INT64). The following code reverses the 4-byte value in a result buffer.

#include <ibase.h>
. . .
for(p = res_buffer; *p != isc_info_end;) {
p++;
length = isc_portable_integer(p, 2);
}

Advance To: