libdballe  9.11
byteswap.h
1 #ifndef DBALLE_CORE_BYTESWAP_H
2 #define DBALLE_CORE_BYTESWAP_H
3 
4 #include "config.h"
5 
6 #if USE_OWN_BSWAP
7 
8 /* byteswap.h - Byte swapping
9  Copyright (C) 2005, 2007, 2009-2011 Free Software Foundation, Inc.
10  Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
11 
12  This program is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 3 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 
25 /* Given an unsigned 16-bit argument X, return the value corresponding to
26  X with reversed byte order. */
27 #define bswap_16(x) ((((x) & 0x00FF) << 8) | \
28  (((x) & 0xFF00) >> 8))
29 
30 /* Given an unsigned 32-bit argument X, return the value corresponding to
31  X with reversed byte order. */
32 #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
33  (((x) & 0x0000FF00) << 8) | \
34  (((x) & 0x00FF0000) >> 8) | \
35  (((x) & 0xFF000000) >> 24))
36 
37 /* Given an unsigned 64-bit argument X, return the value corresponding to
38  X with reversed byte order. */
39 #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
40  (((x) & 0x000000000000FF00ULL) << 40) | \
41  (((x) & 0x0000000000FF0000ULL) << 24) | \
42  (((x) & 0x00000000FF000000ULL) << 8) | \
43  (((x) & 0x000000FF00000000ULL) >> 8) | \
44  (((x) & 0x0000FF0000000000ULL) >> 24) | \
45  (((x) & 0x00FF000000000000ULL) >> 40) | \
46  (((x) & 0xFF00000000000000ULL) >> 56))
47 #else
48 
49 #include <byteswap.h>
50 
51 #endif
52 
53 #endif