00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2007--2009: 00004 Stephane Magnenat <stephane at magnenat dot net> 00005 (http://stephane.magnenat.net) 00006 and other contributors, see authors.txt for details 00007 Mobots group, Laboratory of Robotics Systems, EPFL, Lausanne 00008 00009 This program is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 any other version as decided by the two original authors 00013 Stephane Magnenat and Valentin Longchamp. 00014 00015 This program 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 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 #ifndef __POWER_OF_TWO_H 00025 #define __POWER_OF_TWO_H 00026 00027 // helper functions for power of two numbers 00028 namespace Aseba 00029 { 00032 00034 template <typename T> 00035 bool isPOT(T number) 00036 { 00037 if (number == 0) 00038 return true; 00039 while ((number & 1) == 0) 00040 number >>= 1; 00041 return number == 1; 00042 } 00043 00045 template <typename T> 00046 unsigned shiftFromPOT(T number) 00047 { 00048 unsigned i = 0; 00049 if (number == 0) 00050 return 0; 00051 while ((number & 1) == 0) 00052 { 00053 number >>= 1; 00054 i++; 00055 } 00056 return i; 00057 } 00058 00061 }; // Aseba 00062 00063 #endif