Endianness

Endianness is a data attribute that describes byte order. When applications exchange data, they need to know the ordering convention for multi-byte data. Otherwise, data can be misinterpreted.

Data can have the following byte order formats:

Big endian
A format in which the most significant byte is stored first. The other bytes follow in decreasing order of significance. For example, for a four-byte word, the byte order is 0, 1, 2, 3. For a two-byte word, it is 0, 1.

Big endian format is used by pSeries, IBM® Z, iSeries, Sun, and HP.

Little endian
A format in which the least significant byte is stored first. The other bytes follow in increasing order of significance. For example, for a four-byte word, the byte order is 3, 2, 1, 0. For a two-byte word, it is 1, 0.

Little endian format is used by Intel-based machines, including xSeries.

Endianness affects only multi-byte data. Within a single byte, the bits are always ordered in the same way. Bit order within a byte is always 7, 6, 5, 4, 3, 2, 1, 0.

UTF-8 data is not affected by endianness, even if the data is stored as more than 1 byte. UTF-16 data and UTF-32 data are affected by endianness. For example, the character 'A' is encoded for UTF-16 and UTF-32 as shown in the following table:
Table 1. Example encoding for the character 'A'
  UTF-16 UTF-321
Big endian X'0041' X'00000041'
Little endian X'4100' X'41000000'
Note:
  1. DB2® for z/OS® does not store data in UTF-32

Endianness becomes a potential problem when data is exchanged between systems and applications that use different endian formats and the data is not properly converted. Be aware of the endian format of the data that your system or application handles. You might notice endianness problems when looking at character encoding values in traces. Such a problem might exist if you notice that numeric byte values have been switched. For example, you expect X'0041' but see X'4100'.

Example: Suppose that you are loading data in UTF-16 little endian format (CCSID 1202) from a .NET application. DB2 for z/OS does not support storing data in CCSID 1202. However, DB2 does support conversions to and from CCSID 1202. Thus, DB2 converts the data and stores it in UTF-16 big endian format (CCSID 1200). In this case, you should be aware that the data format has changed.