32 #include "DGtal/base/Common.h"
33 #include "DGtal/base/BasicFunctors.h"
34 #include "DGtal/base/ExpressionTemplates.h"
57 static std::string
bitString(T value,
unsigned nbBits = 0)
63 if(nbBits == 0) nbBits =
sizeof(T)*8;
89 static inline T
mask(
unsigned nthBit)
91 return static_cast<T
>(
static_cast<T
>(1) << nthBit);
98 static inline bool getBit(T key,
unsigned nthBit)
100 return ( key & mask<T>(nthBit) );
108 template <
typename T>
111 return ( (val & -val) | (val & (~val + 1)) );
119 template <
typename T>
122 return ~val & (val + 1);
129 template <
typename T>
133 std::cerr <<
"unsigned int nbSetBits(T val)" << std::endl;
136 for ( ; val; ++i) {val ^= val & -val; }
148 std::cerr <<
"unsigned int nbSetBits( DGtal::uint8_t val )" << std::endl;
161 std::cerr <<
"unsigned int nbSetBits( DGtal::uint16_t val )" << std::endl;
175 std::cerr <<
"unsigned int nbSetBits( DGtal::uint32_t val )" << std::endl;
189 std::cerr <<
"unsigned int nbSetBits( DGtal::uint64_t val )" << std::endl;
321 return ( n & 0xffff )
333 return ( n & 0xffffffffLL )
355 return ( n & 0xff00 )
367 return ( n & 0xffff0000 )
379 return ( n & 0xffffffff00000000LL )
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
boost::uint32_t uint32_t
unsigned 32-bit integer.
boost::uint16_t uint16_t
unsigned 16-bit integer.
boost::uint8_t uint8_t
unsigned 8-bit integer.
boost::uint64_t uint64_t
unsigned 64-bit integer.
static T firstUnsetBit(T val)
static unsigned int indexInSetBits(DGtal::uint8_t n, unsigned int b)
static unsigned int indexInSetBits(DGtal::uint32_t n, unsigned int b)
static unsigned int mostSignificantBit(DGtal::uint8_t n)
static unsigned int leastSignificantBit(DGtal::uint64_t n)
static unsigned int leastSignificantBit(DGtal::uint16_t n)
static unsigned int mostSignificantBit(DGtal::uint64_t n)
static const DGtal::uint8_t myIndexInSetBits[8][256]
static unsigned int leastSignificantBit(DGtal::uint32_t n)
static unsigned int nbSetBits(T val)
static unsigned int leastSignificantBit(DGtal::uint8_t n)
static unsigned int mostSignificantBit(DGtal::uint32_t n)
static T firstSetBit(T val)
static unsigned int indexInSetBits(DGtal::uint64_t n, unsigned int b)
static unsigned int nbSetBits(DGtal::uint64_t val)
static T mask(unsigned nthBit)
static unsigned int nbSetBits(DGtal::uint8_t val)
static unsigned int mostSignificantBit(DGtal::uint16_t n)
static const DGtal::uint8_t myMSB[256]
static unsigned int nbSetBits(DGtal::uint16_t val)
static unsigned int indexInSetBits(DGtal::uint16_t n, unsigned int b)
static unsigned int nbSetBits(DGtal::uint32_t val)
static bool getBit(T key, unsigned nthBit)
static const DGtal::uint8_t myBitCount[256]
static const DGtal::uint8_t myLSB[256]
static std::string bitString(T value, unsigned nbBits=0)
Bits Structs grouping all the functions of this tiny library for bitwise calculation.