Byte swapping and endianness related macros and functions. More...
#include "tuklib_common.h"
Byte swapping and endianness related macros and functions.
This file provides macros or functions to do basic endianness related integer operations (XX = 16, 32, or 64; Y = b or l):
Since they can macros, the arguments should have no side effects since they may be evaluated more than once.
#define bswap32 | ( | num | ) |
( (((uint32_t)(num) << 24) ) \ | (((uint32_t)(num) << 8) & UINT32_C(0x00FF0000)) \ | (((uint32_t)(num) >> 8) & UINT32_C(0x0000FF00)) \ | (((uint32_t)(num) >> 24) ) )
#define bswap64 | ( | num | ) |
( (((uint64_t)(num) << 56) ) \ | (((uint64_t)(num) << 40) & UINT64_C(0x00FF000000000000)) \ | (((uint64_t)(num) << 24) & UINT64_C(0x0000FF0000000000)) \ | (((uint64_t)(num) << 8) & UINT64_C(0x000000FF00000000)) \ | (((uint64_t)(num) >> 8) & UINT64_C(0x00000000FF000000)) \ | (((uint64_t)(num) >> 24) & UINT64_C(0x0000000000FF0000)) \ | (((uint64_t)(num) >> 40) & UINT64_C(0x000000000000FF00)) \ | (((uint64_t)(num) >> 56) ) )