Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

endianness.h

Go to the documentation of this file.
00001 /*
00002  * endianness.h
00003  *
00004  * Endian-dependant encoding/decoding, header
00005  *
00006  * Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V.
00007  *
00008  * Author: Bob Deblier <bob@virtualunlimited.com>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 #ifndef _ENDIANNESS_H
00027 #define _ENDIANNESS_H
00028 
00029 #include "beecrypt.h"
00030 
00031 #ifdef __cplusplus
00032 inline int16_t swap16(int16_t n)
00033 {
00034     return (    ((n & 0xff) << 8) |
00035                 ((n & 0xff00) >> 8) );
00036 }
00037 
00038 inline uint16_t swapu16(uint16_t n)
00039 {
00040     return (    ((n & 0xffU) << 8) |
00041                 ((n & 0xff00U) >> 8) );
00042 }
00043 
00044 inline int32_t swap32(int32_t n)
00045 {
00046     return (    ((n & 0xff) << 24) |
00047                 ((n & 0xff00) << 8) |
00048                 ((n & 0xff0000) >> 8) |
00049                 ((n & 0xff000000) >> 24) );
00050 }
00051 
00052 inline uint32_t swapu32(uint32_t n)
00053 {
00054     return (    ((n & 0xffU) << 24) |
00055                 ((n & 0xff00U) << 8) |
00056                 ((n & 0xff0000U) >> 8) |
00057                 ((n & 0xff000000U) >> 24) );
00058 }
00059 
00060 inline int64_t swap64(int64_t n)
00061 {
00062     return (    ((n & ((int64_t) 0xff)      ) << 56) |
00063                 ((n & ((int64_t) 0xff) <<  8) << 40) |
00064                 ((n & ((int64_t) 0xff) << 16) << 24) |
00065                 ((n & ((int64_t) 0xff) << 24) <<  8) |
00066                 ((n & ((int64_t) 0xff) << 32) >>  8) |
00067                 ((n & ((int64_t) 0xff) << 40) >> 24) |
00068                 ((n & ((int64_t) 0xff) << 48) >> 40) |
00069                 ((n & ((int64_t) 0xff) << 56) >> 56) );
00070 }
00071 #else
00072  int16_t swap16 (int16_t);
00073 uint16_t swapu16(uint16_t);
00074  int32_t swap32 (int32_t);
00075 uint32_t swapu32(uint32_t);
00076  int64_t swap64 (int64_t);
00077 #endif
00078 
00079 #ifdef __cplusplus
00080 extern "C" {
00081 #endif
00082 
00083 #ifdef __cplusplus
00084 }
00085 #endif
00086 
00087 #endif

Generated on Wed Mar 24 13:56:53 2004 for BeeCrypt by doxygen 1.3.6