Digi XBee(R) ANSI C Host Library
Files | Macros | Functions
Byte-swapping functions

Macros for converting between big/little endian and host byte order. More...

Files

file  byteorder.h
 
file  swapbytes.c
 For platforms without swap32() and swap16() functions for swapping byte order for 32 and 16-bit values.
 
file  swapcpy.c
 Used in endian conversions for values larger than 32 bits.
 

Macros

#define be16toh(x)   swap16(x)
 Convert a uint16_t in big-endian byte order to host byte order.
 
#define be32toh(x)   swap32(x)
 Convert a uint32_t in big-endian byte order to host byte order.
 
#define htobe16(x)   swap16(x)
 Convert a uint16_t in host byte order to big-endian byte order.
 
#define htobe32(x)   swap32(x)
 Convert a uint32_t in host byte order to big-endian byte order.
 
#define htole16(x)   (x)
 Convert a uint16_t in host byte order to little-endian byte order.
 
#define htole32(x)   (x)
 Convert a uint32_t in host byte order to little-endian byte order.
 
#define le16toh(x)   (x)
 Convert a uint16_t in little-endian byte order to host byte order.
 
#define le32toh(x)   (x)
 Convert a uint32_t in little-endian byte order to host byte order.
 
#define memcpy_betoh(dst, src_be, count)   _swapcpy( dst, src_be, count)
 Copy count bytes in big-endian byte order from src_be to dst in host byte order (equivalent to memcpy() on big-endian platforms).
 
#define memcpy_betole(dst_le, src_be, count)   _swapcpy( dst_le, src_be, count)
 Copy count bytes in big-endian byte order from src_be to dst_le in little-endian byte order (always swaps byte order).
 
#define memcpy_htobe(dst_be, src, count)   _swapcpy( dst_be, src, count)
 Copy count bytes in host byte order from src to dst_be in big-endian byte order (equivalent to memcpy() on big-endian platforms).
 
#define memcpy_htole(dst_le, src, count)   _f_memcpy( dst_le, src, count)
 Copy count bytes in host byte order from src to dst_le in little-endian byte order (equivalent to memcpy() on little-endian platforms).
 
#define memcpy_letobe(dst_be, src_le, count)   _swapcpy( dst_be, src_le, count)
 Copy count bytes in little-endian byte order from src_le to dst_be in big-endian byte order (always swaps byte order).
 
#define memcpy_letoh(dst, src_le, count)   _f_memcpy( dst, src_le, count)
 Copy count bytes in little-endian byte order from src_le to dst in host byte order (equivalent to memcpy() on little-endian platforms).
 

Functions

uint16_t swap16 (uint16_t value)
 Swap the byte order of a 16-bit value. More...
 
uint32_t swap32 (uint32_t value)
 Swap the byte order of a 32-bit value. More...
 
void _swapcpy (void FAR *dst, const void FAR *src, uint_fast8_t count)
 Function similar to memcpy() but reverses byte order during copy. Copy count from src to dst while reversing the order. Assumes that src and dst do not overlap. More...
 

Detailed Description

Macros for converting between big/little endian and host byte order.

Function Documentation

void _swapcpy ( void FAR dst,
const void FAR src,
uint_fast8_t  count 
)

Function similar to memcpy() but reverses byte order during copy. Copy count from src to dst while reversing the order. Assumes that src and dst do not overlap.

Parameters
[out]dstdestination buffer
[in]srcsource buffer
[in]countnumber of bytes to copy

References FAR.

Referenced by _xbee_checksum_inline().

uint16_t swap16 ( uint16_t  value)

Swap the byte order of a 16-bit value.

Parameters
[in]valuevalue to swap
Returns
new 16-bit value with opposite endianness of value
uint32_t swap32 ( uint32_t  value)

Swap the byte order of a 32-bit value.

Parameters
[in]valuevalue to swap
Returns
new 32-bit value with opposite endianness of value