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