1 /*! ========================================================================
2 ** Extended Template Library
3 ** Bit Rotation Implementation
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
23 ** These template functions have not yet been throughly tested,
24 ** and may be inaccurate or just plain wrong. You have been warned.
26 ** ========================================================================= */
28 /* === S T A R T =========================================================== */
30 #ifndef __ETL_BIT_ROTATE_H
31 #define __ETL_BIT_ROTATE_H
33 /* === H E A D E R S ======================================================= */
35 /* === M A C R O S ========================================================= */
37 /* === T Y P E D E F S ===================================================== */
39 /* === C L A S S E S & S T R U C T S ======================================= */
43 template <typename T> T
44 rot_left(const T &val, const int &bits=1)
46 return (T)( ((unsigned)val<<bits)+((unsigned)val>>(sizeof(T)*8-bits)) );
49 template <typename T> T
50 rot_right(const T &val, const int &bits=1)
52 return (T)( ((unsigned)val>>bits)+((unsigned)val<<(sizeof(T)*8-bits)) );
57 /* === E X T E R N S ======================================================= */
59 /* === E N D =============================================================== */