tlx
bswap_le.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/math/bswap_le.hpp
3 *
4 * bswap16_le(), bswap32_le() and bswap64_le() to swap bytes to little-endian:
5 * no-operations on little-endian systems, bswaps on big-endian systems.
6 *
7 * Part of tlx - http://panthema.net/tlx
8 *
9 * Copyright (C) 2018 Timo Bingmann <tb@panthema.net>
10 *
11 * All rights reserved. Published under the Boost Software License, Version 1.0
12 ******************************************************************************/
13
14#ifndef TLX_MATH_BSWAP_LE_HEADER
15#define TLX_MATH_BSWAP_LE_HEADER
16
17#include <tlx/define/endian.hpp>
18#include <tlx/math/bswap.hpp>
19
20namespace tlx {
21
22//! \addtogroup tlx_math
23//! \{
24
25/******************************************************************************/
26// bswap16_le() - swap 16-bit integers to little-endian
27
28#if TLX_LITTLE_ENDIAN
29static inline uint16_t bswap16_le(const uint16_t& v) {
30 return v;
31}
32#elif TLX_BIG_ENDIAN
33static inline uint16_t bswap16_le(const uint16_t& v) {
34 return bswap16(v);
35}
36#endif
37
38/******************************************************************************/
39// bswap32_le() - swap 32-bit integers to little-endian
40
41#if TLX_LITTLE_ENDIAN
42static inline uint32_t bswap32_le(const uint32_t& v) {
43 return v;
44}
45#elif TLX_BIG_ENDIAN
46static inline uint32_t bswap32_le(const uint32_t& v) {
47 return bswap32(v);
48}
49#endif
50
51/******************************************************************************/
52// bswap64_le() - swap 64-bit integers to little-endian
53
54#if TLX_LITTLE_ENDIAN
55static inline uint64_t bswap64_le(const uint64_t& v) {
56 return v;
57}
58#elif TLX_BIG_ENDIAN
59static inline uint64_t bswap64_le(const uint64_t& v) {
60 return bswap64(v);
61}
62#endif
63
64/******************************************************************************/
65
66//! \}
67
68} // namespace tlx
69
70#endif // !TLX_MATH_BSWAP_LE_HEADER
71
72/******************************************************************************/
static uint32_t bswap32(const uint32_t &v)
bswap32 - generic
Definition: bswap.hpp:84
static uint16_t bswap16(const uint16_t &v)
bswap16 - generic
Definition: bswap.hpp:52
static uint64_t bswap64(const uint64_t &v)
bswap64 - generic
Definition: bswap.hpp:122