# MI_SwapEndian*

## Syntax

      #include <nitro/mi.h>

      #define MI_SwapEndian8(val)  (u8)(val)
      #define MI_SwapEndian16(val) (u16)((((val) & 0xFF00UL) >> 8UL) | (((val) & 0x00FFUL) << 8UL))
      #define MI_SwapEndian32(val) (u32)(                                 \
                                      (((val) & 0xFF000000UL) >> 24UL) |  \
                                      (((val) & 0x00FF0000UL) >>  8UL) |  \
                                      (((val) & 0x0000FF00UL) <<  8UL) |  \
                                      (((val) & 0x000000FFUL) << 24UL) )
      #define MI_SwapEndian64(val) (u64)(                                         \
                                    (((val) & 0xFF00000000000000ULL) >> 56ULL)    \
                                  | (((val) & 0x00FF000000000000ULL) >> 40ULL)    \
                                  | (((val) & 0x0000FF0000000000ULL) >> 24ULL)    \
                                  | (((val) & 0x000000FF00000000ULL) >>  8ULL)    \
                                  | (((val) & 0x00000000FF000000ULL) <<  8ULL)    \
                                  | (((val) & 0x0000000000FF0000ULL) << 24ULL)    \
                                  | (((val) & 0x000000000000FF00ULL) << 40ULL)    \
                                  | (((val) & 0x00000000000000FFULL) << 56ULL) )

## Arguments

val | The value whose endianity is to be converted. Note: Because this is a macro, evaluation is performed several times.

## Return Values

Value for which endianness was converted (`u16, u32, u64`).

## Description

Converts the endian of the specified (16-, 32-, or 64-bit) value. If little endian is detected before conversion, big endian results after conversion.
Note: Because this is a macro, arguments are evaluated several times.

These 8-bit versions do not actually perform any conversions, but they have been included for uniform source code visibility.

## See Also

`MI_Load*
MI_Store*
MI_HTo*
MI_*ToH*`

## Revision History

2007/11/21 Added a description of the 64-bit version.
2006/06/13 Added a description of the 8-bit version.
2006/04/05 Initial version.

CONFIDENTIAL