00001 /* byteswap.h - Byte swapping 00002 Copyright (C) 2005, 2007 Free Software Foundation, Inc. 00003 Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005. 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU Lesser General Public License as published by 00007 the Free Software Foundation; either version 2.1 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00017 00018 #ifndef _GL_BYTESWAP_H 00019 #define _GL_BYTESWAP_H 00020 00021 /* Given an unsigned 16-bit argument X, return the value corresponding to 00022 X with reversed byte order. */ 00023 #define bswap_16(x) ((((x) & 0x00FF) << 8) | \ 00024 (((x) & 0xFF00) >> 8)) 00025 00026 /* Given an unsigned 32-bit argument X, return the value corresponding to 00027 X with reversed byte order. */ 00028 #define bswap_32(x) ((((x) & 0x000000FF) << 24) | \ 00029 (((x) & 0x0000FF00) << 8) | \ 00030 (((x) & 0x00FF0000) >> 8) | \ 00031 (((x) & 0xFF000000) >> 24)) 00032 00033 /* Given an unsigned 64-bit argument X, return the value corresponding to 00034 X with reversed byte order. */ 00035 #define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \ 00036 (((x) & 0x000000000000FF00ULL) << 40) | \ 00037 (((x) & 0x0000000000FF0000ULL) << 24) | \ 00038 (((x) & 0x00000000FF000000ULL) << 8) | \ 00039 (((x) & 0x000000FF00000000ULL) >> 8) | \ 00040 (((x) & 0x0000FF0000000000ULL) >> 24) | \ 00041 (((x) & 0x00FF000000000000ULL) >> 40) | \ 00042 (((x) & 0xFF00000000000000ULL) >> 56)) 00043 00044 #endif /* _GL_BYTESWAP_H */