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