sl@0: // ------------------------------------- sl@0: // lowest_bit.hpp sl@0: // sl@0: // Position of the lowest bit 'on' sl@0: // sl@0: // (C) Copyright Gennaro Prota 2003 - 2004. sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. sl@0: // (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // ------------------------------------------------------ sl@0: sl@0: #ifndef BOOST_LOWEST_BIT_HPP_GP_20030301 sl@0: #define BOOST_LOWEST_BIT_HPP_GP_20030301 sl@0: sl@0: #include sl@0: #include "boost/pending/integer_log2.hpp" sl@0: sl@0: sl@0: namespace boost { sl@0: sl@0: template sl@0: int lowest_bit(T x) { sl@0: sl@0: assert(x >= 1); // PRE sl@0: sl@0: // clear all bits on except the rightmost one, sl@0: // then calculate the logarithm base 2 sl@0: // sl@0: return boost::integer_log2( x - ( x & (x-1) ) ); sl@0: sl@0: } sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: #endif // include guard