Byte Order Macros

Name

Byte Order Macros -- a portable way to convert between different byte orders.

Synopsis

#include <tiffep.h> (macros.h)


#define     LSW                         (l)
#define     MSW                         (l)
#define     LSB                         (w)
#define     MSB                         (w)
#define     LSN                         (b)
#define     MSN                         (b)
#define     BCD                         (val)

#define     L_NIBBLE2BYTE               (u, l)
#define     L_NIBBLE2WORD               (ll, lu, ul, uu)
#define     L_BYTE2WORD                 (l, u)
#define     L_BYTE2LONGWORD             (ll, lu, ul, uu)
#define     L_WORD2LONGWORD             (l, u)

#define     B_NIBBLE2BYTE               (u, l)
#define     B_NIBBLE2WORD               (uu, ul, lu, ll)
#define     B_BYTE2WORD                 (u, l)
#define     B_BYTE2LONGWORD             (uu, ul, lu, ll)
#define     B_WORD2LONGWORD             (u, l)

Description

These macros provide a portable way to determine the host byte order and to convert values between different byte orders.

The byte order is the order in which bytes are stored to create larger data types such as the word and longword values. The host byte order is the byte order used on the current machine.

Some processors store the most significant bytes (i.e. the bytes that hold the largest part of the value) first. These are known as big-endian processors.

Other processors (notably the x86 family) store the most significant byte last. These are known as little-endian processors.

Finally, to complicate matters, some other processors store the bytes in a rather curious order known as PDP-endian. For a 4-byte word, the 3rd most significant byte is stored first, then the 4th, then the 1st and finally the 2nd.
 

Details

LSW()

#define     LSW(l)

Extract the least significant word from the longword.

 
l : a longword value (32 bits).
Returns : the least significant word.