Botan

Bit/Word Operations

License
Botan is released under the Simplified BSD License (see LICENSE.md)

bool  isPowerOf2(T)(T arg);

Power of 2 test. T should be an uinteger type

Parameters
T arg an integer value
Returns
true iff arg is 2^n for some n > 0

size_t  highBit(T)(T n);

Return the index of the highest set bit T is an uinteger type

Parameters
T n an integer value
Returns
index of the highest set bit in n

size_t  lowBit(T)(T n);

Return the index of the lowest set bit T is an uinteger type

Parameters
T n an integer value
Returns
index of the lowest set bit in n

size_t  significantBytes(T)(T n);

Return the number of significant bytes in n

Parameters
T n an integer value
Returns
number of significant bytes in n

size_t  hammingWeight(T)(T n);

Compute Hamming weights

Parameters
T n an integer value
Returns
number of bits in n set to 1

size_t  ctz(T)(T n);

Count the trailing zero bits in n

Parameters
T n an integer value
Returns
maximum x st 2^x divides n